ruby - 在 vim 或 macvim 中运行 cucumber 测试

标签 ruby testing vim cucumber macvim

我最近才开始使用 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/

相关文章:

ruby - 为瘦服务器和 sinatra 启用 SSL

ruby SSH : interactive command "su": How further after successfull logged in?

ruby - 是否可以在 proc 中查看 ruby​​ 代码?

ruby - 如何在ruby gem SearchKick中将字段添加到ElasticSearch以便按顺序排序

email - selenium 可以用于测试 Microsoft Outlook 中电子邮件的电子邮件内容吗

iphone - 如何在销售日期之前分发 iPhone 应用程序而不获取 UDID 或越狱?

linux - CentOS 7's vim can' 无法打开帮助(以 root 身份运行时),因为它无法处理 gzip 压缩的帮助文件

java - 如何访问 Selenium 中 <td> 中动态生成的文本?

vim - 如何在Vim中删除每行末尾的换行符?

Vim 显示垃圾字符