Created
January 2, 2013 16:28
-
-
Save st23am/4435837 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
" 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