2013-10-12 20 views
3

我刚刚开始使用VIM作为我的主编。我到目前为止发现了很多有趣的小功能。我一直在寻找几天的时间来从编辑器中运行我的黄瓜测试(如果它可以运行特定的场景,那就是奖金)。我尝试过像vim-cucumber和vim-vroom这样的插件,但是我似乎无法让事情顺利进行。注意:我在env.rb中执行“Rake”命令,这可能是为什么插件无法正常工作。只是想知道是否有人在同一条船上,并有解决方案,任何帮助,将不胜感激。在vim或macvim中运行黄瓜测试

感谢 亚历克斯

回答

2

我建立映射,当我键入,t我的光标下的RSpec的或黄瓜测试运行,当我输入,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                       
1

这可能会让一些烦人的,但我喜欢重新映射我的测试键来运行特定文件的规格。所以我会运行在我的会议

:map ,t :w\|:!cucumber features/my_cucumber_feature.feature<cr> 

这样,我只能考什么我的工作,而不是测试所有文件以下。我喜欢这种方法,因为我可以在我的项目的任何地方编辑任何文件,它仍然只会运行我希望它运行的测试。基本上它说,保存我所在的任何文件并运行规格。如果我运行单元测试我将其更改为:

:map ,t :w\|:!rspec spec/models/my_model_spec.rb<cr> 

我喜欢快速的反馈,所以我想只运行涉及到我的情况的测试,而不是整个套件。我将在最后运行整个套件以确保我没有错过任何东西。