我最近才开始使用 VIM 作为我的主编辑器。到目前为止,我在发现它提供的所有不错的小功能时玩得很开心。我一直在寻找几天来从编辑器中运行我的 cucumber 测试(如果它可以运行特定场景,这是一个奖励)。我尝试过像 vim-cucumber 和 vim-vroom 这样的插件,但我似乎无法正常工作。注意:我在 env.rb 中做一些事情,比如运行“Rake”命令,这可能是插件不工作的原因。只是想知道是否有人在同一条船上并且有解决方案,我们将不胜感激任何帮助。
谢谢 亚历克斯
最佳答案
当我键入 ,t
时,我设置了映射,我的光标下的 rspec 或 cucumber 测试运行,当我键入 ,T
时,整个文件我' m 在运行。如果我在不在 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
关于ruby - 在 vim 或 macvim 中运行 cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336301/