Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Forked from moro/rspec.vim
Created July 31, 2009 11:00
Show Gist options
  • Save amatsuda/159178 to your computer and use it in GitHub Desktop.
Save amatsuda/159178 to your computer and use it in GitHub Desktop.
function! s:RunRspec (opts)
let rails_spec_path_re = '\<spec/\(models\|controllers\|views\|helpers\)/.*_spec\.rb$'
if( expand('%') =~ rails_spec_path_re && filereadable('script/spec') )
"let command = '!ruby script/spec '
let spec_command = '!rspec '
if filereadable('tmp/pids/spec_server.pid')
let spec_command = spec_command . ' --drb '
endif
else
let spec_command = '!rspec '
endif
exe spec_command . a:opts . ' ' . expand('%:p')
endfunction
function! s:RunCucumber (feature)
if( filereadable('Rakefile') )
let command = '!rake features FEATURE='
elseif( filereadable('script/cucumber') )
let command = '!script/cucumber --language ja '
else
let command = '!cucumber --language ja '
endif
exe command . a:feature
endfunction
function! <SID>RunBehavior ()
call s:RunRspec('--format=n --color')
endfunction
function! <SID>RunExample ()
call s:RunRspec('--format=n --color --line ' . line('.'))
endfunction
function! <SID>RunScenario ()
call s:RunCucumber(expand('%:p') . ':' . line('.'))
endfunction
function! <SID>RunFeature ()
call s:RunCucumber(expand('%:p'))
endfunction
function! s:SetupCucumberVim ()
command! RunFeature call <SID>RunFeature()
command! RunScenario call <SID>RunScenario()
nnoremap -fe :RunFeature<CR>
nnoremap -sc :RunScenario<CR>
endfunction
function s:SetupRspecVim()
command! RunExample call <SID>RunExample()
command! RunBehavior call <SID>RunBehavior()
nnoremap -ex :RunExample<CR>
nnoremap -bh :RunBehavior<CR>
endfunction
" TODO script localにする
au BufRead,BufNewFile *_spec.rb call s:SetupRspecVim()
au BufRead,BufNewFile *.feature call s:SetupCucumberVim()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment