Created
July 18, 2013 18:21
-
-
Save djohnsonjr/6031651 to your computer and use it in GitHub Desktop.
Vimrc to run current file with turn (instead of ruby) and run the current 'it' test if applicable. Based on https://github.com/r00k/dotfiles/blob/master/vimrc
I am using turn because the name matcher is not working for me with ruby.
This file contains 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
map <Leader>s :w<cr>:call RunCurrentTest()<CR> | |
map <Leader>ss :w<cr>:call RunCurrentLineInTest()<CR> | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 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("!bin/cucumber") | |
exec g:bjo_test_runner g:bjo_test_file | |
elseif match(expand('%'), '_spec\.rb$') != -1 | |
call SetTestRunner("!bin/rspec") | |
exec g:bjo_test_runner g:bjo_test_file | |
else | |
call SetTestRunner("!turn -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! SetTestFile() | |
let g:bjo_test_file=@% | |
endfunction | |
function! RunCurrentLineInTest() | |
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1 | |
if in_test_file | |
call SetTestFileWithLine() | |
end | |
exec "!turn -Itest" g:bjo_test_file . " -n /" . g:bjo_test_file_line . "/" | |
endfunction | |
function! SetTestFileWithLine() | |
let g:bjo_test_file=@% | |
let rawline = getline(".") | |
let rawline = substitute(rawline, ".*it '", "", "") | |
let rawline = substitute(rawline, "' do", "", "") | |
let g:bjo_test_file_line = substitute(rawline, " ", ".", "g") | |
endfunction | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes that you are using minitest & turn gems and spec style minitest. I am actually using minitest-rails
I was not able to get the minitest-focus gem to work or to get the -n option working with ruby directly.
This requires that your cursor is on the 'it' line.