Created
March 12, 2014 19:08
-
-
Save orthodoc/9514046 to your computer and use it in GitHub Desktop.
This file contains 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
" Vim functions to run RSpec and Cucumber on the current file and optionally on | |
" the spec/scenario under the cursor. | |
function! RailsScriptIfExists(name) | |
" Bundle exec | |
if isdirectory(".bundle") || (exists("b:rails_root") && isdirectory(b:rails_root . "/.bundle")) | |
return "bundle exec " . a:name | |
" System Binary | |
else | |
return a:name | |
end | |
endfunction | |
function! RunSpec(args) | |
let spec = RailsScriptIfExists("rspec --drb") | |
let cmd = spec . " " . a:args . " -fn -c " . @% | |
execute ":! echo " . cmd . " && " . cmd | |
endfunction | |
function! RunCucumber(args) | |
let cucumber = RailsScriptIfExists("cucumber --drb") | |
let cmd = cucumber . " " . @% . a:args | |
execute ":! echo " . cmd . " && " . cmd | |
endfunction | |
function! RunTestFile(args) | |
if @% =~ "\.feature$" | |
call RunCucumber("" . a:args) | |
elseif @% =~ "\.rb$" | |
call RunSpec("" . a:args) | |
end | |
endfunction | |
function! RunTest(args) | |
if @% =~ "\.feature$" | |
call RunCucumber(":" . line('.') . a:args) | |
elseif @% =~ "\.rb$" | |
call RunSpec("-l " . line('.') . a:args) | |
end | |
endfunction | |
map <Leader>; :call RunTest("")<CR> | |
map <Leader>' :call RunTestFile("")<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment