Skip to content

Instantly share code, notes, and snippets.

@trekdemo
Created February 8, 2013 11:31
Show Gist options
  • Save trekdemo/4738309 to your computer and use it in GitHub Desktop.
Save trekdemo/4738309 to your computer and use it in GitHub Desktop.
Run cucumber and rspec from vim
#!/bin/sh
#
# Run specs with great speed and daring-do.
#
if [ -f zeus.json ]; then
zeus cucumber "$@"
else
bundle exec cucumber "$@"
fi
#!/bin/sh
#
# Run specs with great speed and daring-do.
#
if [ -f zeus.json ]; then
zeus rspec "$@"
else
bundle exec rspec "$@"
fi
augroup ft_ruby
au!
au Filetype ruby nnoremap <buffer> <Leader>ts :call RunCurrentSpecFile()<CR>
au Filetype ruby nnoremap <buffer> <Leader>s :call RunNearestSpec()<CR>
au Filetype ruby nnoremap <buffer> <Leader>l :call RunLastSpec()<CR>
augroup END
augroup ft_cucumber
au!
au Filetype cucumber nnoremap <buffer> <Leader>ts :call RunCurrentFeatureFile()<CR>
au Filetype cucumber nnoremap <buffer> <Leader>s :call RunNearestFeature()<CR>
au Filetype cucumber nnoremap <buffer> <Leader>l :call RunLastFeature()<CR>
augroup END
" Rails {{{
cabbrev rake Rake
cabbrev rails Rails
cabbrev bundle Bundle
" rspec mappings
function! RunCurrentSpecFile()
if InSpecFile()
let l:command = "s " . " -f documentation " . @%
call SetLastSpecCommand(l:command)
call RunSpecs(l:command)
endif
endfunction
function! RunNearestSpec()
if InSpecFile()
let l:command = "s " . " -l " . line(".") . " -f documentation " . @%
call SetLastSpecCommand(l:command)
call RunSpecs(l:command)
endif
endfunction
function! RunLastSpec()
if exists("t:last_spec_command")
call RunSpecs(t:last_spec_command)
endif
endfunction
function! InSpecFile()
return match(expand("%"), "_spec.rb$") != -1
endfunction
function! SetLastSpecCommand(command)
let t:last_spec_command = a:command
endfunction
function! RunSpecs(command)
if has('gui_running')
execute ":w"
execute "!". a:command
else
execute ":w\|!clear && echo " . a:command . " && echo && " . a:command
endif
endfunction
" }}}
" Cucumber {{{
function! RunCurrentFeatureFile()
if InFeatureFile()
let l:command = "cuc " . @%
call SetLastFeatureCommand(l:command)
call RunFeatures(l:command)
endif
endfunction
function! RunNearestFeature()
if InFeatureFile()
let l:command = "cuc " . " -l " . line(".") . " " . @%
call SetLastFeatureCommand(l:command)
call RunFeatures(l:command)
endif
endfunction
function! RunLastFeature()
if exists("t:last_feature_command")
call RunFeatures(t:last_feature_command)
endif
endfunction
function! InFeatureFile()
return match(expand("%"), ".feature$") != -1
endfunction
function! SetLastFeatureCommand(command)
let t:last_feature_command = a:command
endfunction
function! RunFeatures(command)
if has('gui_running')
execute ":w"
execute "!". a:command
else
execute ":w\|!clear && echo " . a:command . " && echo && " . a:command
endif
endfunction
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment