Created
June 20, 2011 20:13
-
-
Save jeffrydegrande/1036464 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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