Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created February 14, 2014 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcrayford/8999630 to your computer and use it in GitHub Desktop.
Save tcrayford/8999630 to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment