我最近开始使用VIM作为我的主要编辑器,目前我非常开心地发现它提供的所有不错的小功能。我已经寻找了几天了,想找到一种从编辑器中运行我的cucumber测试的方法(如果可以运行特定的场景就更好了)。我尝试过像vim-cucumber和vim-vroom这样的插件,但似乎无法使它们正常工作。注意:我在env.rb中运行"Rake"命令,这可能是插件无法工作的原因。只是想知道是否有人遇到过同样的问题,并且有没有解决方案。非常感谢任何帮助。
谢谢 Alex
谢谢 Alex
,t
时,我的光标下方的rspec或cucumber测试就会运行;当我输入 ,T
时,运行整个文件。如果我不在rspec或cucumber文件中但仍然输入,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
这可能会让一些人感到烦恼,但我喜欢将我的测试键重新映射为运行特定文件的规范。所以我会在我的会话中运行以下内容。
:map ,t :w\|:!cucumber features/my_cucumber_feature.feature<cr>
:map ,t :w\|:!rspec spec/models/my_model_spec.rb<cr>
我喜欢快速反馈,因此只运行与我的情况相关的测试而不是整个套件。最后我会运行整个套件以确保没有遗漏。