Skip to content

Instantly share code, notes, and snippets.

@dasch
Created September 13, 2012 08:16
Show Gist options
  • Save dasch/3712824 to your computer and use it in GitHub Desktop.
Save dasch/3712824 to your computer and use it in GitHub Desktop.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
noremap <leader>l :call RunTestFile()<cr>
noremap <leader>; :call RunNearestTest()<cr>
noremap <leader>o :call RunTests('')<cr>
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.rb\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
let t:grb_test_file = AlternateForCurrentFile()
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
if filereadable(a:filename)
:w
end
if match(a:filename, '_test\.rb$') != -1
exec ":!testrb -Itest -I. " . a:filename
else
exec ":!bundle exec rspec " . a:filename
end
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment