3

是否有任何已知的 Vim 插件可以通过分别显示绿色或红色条来显示 Rails 测试是通过还是失败。我个人觉得 Growl 通知很让人分心,正在寻找替代方案,但找不到任何东西。与此类似的东西是我的目标。.

编辑:我在 OSX 10.6 上使用 MacVim

4

2 回答 2

0

这是我的$VIMFILES/ftplugin/python/tests.vim文件中的内容:

function! RunAllTests(args)
    silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
    if filereadable(getcwd() . "/runtests.py")
        set makeprg=./runtests.py\ --with-machineout
    elseif filereadable(getcwd() . "/manage.py") && filereadable(getcwd() . "/settings.py")
        set makeprg=./manage.py\ test\ --with-machineout\ --verbosity=0
    else
        set makeprg=nosetests\ --with-machineout
    endif
    exec "make! " . a:args
endfunction

function! JumpToError()
    if getqflist() != []
        for error in getqflist()
            if error['valid']
                break
            endif
        endfor
        let error_message = substitute(error['text'], '^ *', '', 'g')
        silent cc!
        if error['bufnr'] != 0
            exec ":sbuffer " . error['bufnr']
        endif
        call RedBar()
        echo error_message
    else
        call GreenBar()
        echo "All tests passed"
    endif
endfunction

function! RedBar()
    hi RedBar ctermfg=white ctermbg=red guibg=red
    echohl RedBar
    echon repeat(" ",&columns - 1)
    echohl None
endfunction

function! GreenBar()
    hi GreenBar ctermfg=white ctermbg=green guibg=green
    echohl GreenBar
    echon repeat(" ",&columns - 1)
    echohl None
endfunction

let maplocalleader=","
nmap <LocalLeader>a :call RunAllTests("--machine-out")<cr>:redraw<cr>:call JumpToError()<cr>
nmap <LocalLeader>A :call RunAllTests("")<cr>

我最初基于 Gary 的 .vimrc,然后移动了一些东西并重新编码了显示条的方法。

我确信它可以很容易地适应 ruby​​ 以及它用于测试运行的任何东西(我不是 ruby​​ 人)。这目前使用nosetests来运行python 测试。

希望有帮助!

于 2012-07-11T14:18:43.837 回答
0

你试过Autotest::Screen吗?

我不是红宝石人,但诀窍并没有那么复杂。您需要做的就是检测特定项目目录下的文件更改,运行您的测试,然后将测试结果带回屏幕的状态栏。

于 2012-07-08T10:33:24.967 回答