Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
running specs while on vim
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeek committed Oct 17, 2012
1 parent d76a7dc commit ae99fea
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions vimrc
Expand Up @@ -196,3 +196,45 @@ endfunction

" mapping for function above
map <leader>bw :call Wipeout()<CR>
" functions ro run tests under rails project
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !echo;echo;echo;echo;echo
exec ":!bundle exec rspec " . 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 . " --format=spec")
endfunction

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

" Run this file
map <leader>r :call RunTestFile()<cr>
" Run only the example under the cursor
map <leader>R :call RunNearestTest()<cr>
" Run all test files
map <leader>a :call RunTests('spec')<cr>

0 comments on commit ae99fea

Please sign in to comment.