Skip to content

Instantly share code, notes, and snippets.

@moro
Created June 26, 2009 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moro/136245 to your computer and use it in GitHub Desktop.
Save moro/136245 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 = '!spec '
if filereadable('tmp/pids/spec_server.pid')
let spec_command = spec_command . ' --drb '
endif
else
let spec_command = '!spec '
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