Skip to content

Instantly share code, notes, and snippets.

@st23am
Created January 2, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st23am/4435837 to your computer and use it in GitHub Desktop.
Save st23am/4435837 to your computer and use it in GitHub Desktop.
" Thanks to Ben Orenstein
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Test-running stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RunCurrentTest()
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
if match(expand('%'), '\.feature$') != -1
call SetTestRunner("!bundle exec cucumber")
exec g:bjo_test_runner g:bjo_test_file
elseif match(expand('%'), '_spec\.rb$') != -1
call SetTestRunner("!bundle exec rspec")
exec g:bjo_test_runner g:bjo_test_file
else
call SetTestRunner("!bundle exec ruby -Itest")
exec g:bjo_test_runner g:bjo_test_file
endif
else
exec g:bjo_test_runner g:bjo_test_file
endif
endfunction
function! SetTestRunner(runner)
let g:bjo_test_runner=a:runner
endfunction
function! RunCurrentLineInTest()
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFileWithLine()
end
exec "!bundle exec rspec" g:bjo_test_file . ":" . g:bjo_test_file_line
endfunction
function! SetTestFile()
let g:bjo_test_file=@%
endfunction
function! SetTestFileWithLine()
let g:bjo_test_file=@%
let g:bjo_test_file_line=line(".")
endfunction
function! CorrectTestRunner()
if match(expand('%'), '\.feature$') != -1
return "cucumber"
elseif match(expand('%'), '_spec\.rb$') != -1
return "rspec"
else
return "ruby"
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <C-d> :call RunCurrentTest()<cr>
" Set up some useful Rails.vim bindings for working with Backbone.js
autocmd User Rails Rnavcommand template app/assets/templates -glob=**/* -suffix=.jst.ejs
autocmd User Rails Rnavcommand jmodel app/assets/javascripts/models -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jview app/assets/javascripts/views -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jcollection app/assets/javascripts/collections -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jrouter app/assets/javascripts/routers -glob=**/* -suffix=.coffee
autocmd User Rails Rnavcommand jspec spec/javascripts -glob=**/* -suffix=.coffee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment