Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created June 20, 2011 20:13
Show Gist options
  • Save jeffrydegrande/1036464 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/1036464 to your computer and use it in GitHub Desktop.
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !echo;echo;echo;echo;echo
exec ":!bundle exec rspec --fail-fast --drb " . a:filename
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_spec_file = match(expand("%"), '_spec.rb$') != -1
if in_spec_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number)
endfunction
" Run this file
map <leader>t :call RunTestFile()<cr>
" Run only the example under the cursor
map <leader>T :call RunNearestTest()<cr>
" Run all test files
map <leader>a :call RunTests('spec')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment