나는 것과 매핑을 설정하고, 내가 ,T
를 입력 할 때 나는에있어 전체 파일이 실행됩니다. 내가 rspec 또는 오이 파일에 없을 때 ,t
을 입력하면 마지막으로 실행 한 테스트가 다시 실행됩니다. 여기 내 vimrc의 관련 부분이 있습니다.
" Set the leader
let mapleader = ","
" Run tests
autocmd FileType ruby,eruby,yaml,haml,scss,cucumber nmap <leader>t :call RunTestCommand(line('.'))<CR>
autocmd FileType ruby,eruby,yaml,haml,scss,cucumber nmap <leader>T :call RunTestCommand()<CR>
function! GetTestCommand()
if expand('%:r') =~ '_spec$'
return 'bundle exec rspec'
elseif expand('%') =~ '\.feature$'
return 'bundle exec cucumber'
else
return '0'
endif
endfunction
function! RunTestCommand(...)
let cmd = GetTestCommand()
" if there's a command update the test command register (t)
if cmd != '0'
let @t = ':!' . cmd . ' ' . expand('%') . (a:0 == 1 ? ':'.line('.') : '')
endif
" if the test command register isn't empty, excecute it.
if strlen(@t) > 0
execute @t
elseif
echoerr "No test command to run"
end
endfunction