Skip to content

Instantly share code, notes, and snippets.

@tom-pang
Created February 14, 2014 11:33
Show Gist options
  • Select an option

  • Save tom-pang/8999630 to your computer and use it in GitHub Desktop.

Select an option

Save tom-pang/8999630 to your computer and use it in GitHub Desktop.

Revisions

  1. tom-pang created this gist Feb 14, 2014.
    50 changes: 50 additions & 0 deletions vimrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    function! RunTests(filename)
    " Write the file and run tests for the given filename
    :w
    if match(a:filename, '\.feature$') != -1
    :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
    exec ":!bundle exec cucumber " . a:filename
    elseif match(a:filename, '\.coffee$') != -1
    :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
    exec "!jasmine-headless-webkit " . a.filename
    else
    :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
    if filereadable("script/test")
    exec ":!script/test " . a:filename
    else
    exec ":!bundle exec rspec -c " . a:filename
    end
    end
    endfunction

    function! SetTestFile()
    " Set the spec file that tests will be run for.

    let t:grb_test_file=@%
    endfunction

    function! RunTestFile(...)
    if a:0
    let command_suffix = a:1
    else
    let command_suffix = ""
    endif

    " Run the tests for the previously-marked file.
    let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|.*test.*.clj\|Spec.js\|.*Spec.*.hs\|.*Test.*hs\)$') != -1
    if in_test_file
    call SetTestFile()
    elseif !exists("t:grb_test_file")
    call RunTests('')
    return
    end
    call RunTests(t:grb_test_file . command_suffix)
    endfunction

    function! RunNearestTest()
    let spec_line_number = line('.')
    call RunTestFile(":" . spec_line_number)
    endfunction

    map <cr> :call RunTestFile()<cr>
    map <leader><cr> :call RunNearestTest()<cr>