Ⅰ. 插件描述
Run your tests with a single keystroke! Tighten your TDD feedback loop!Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'botandrose/vim-testkey'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'botandrose/vim-testkey'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'botandrose/vim-testkey'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/botandrose/vim-testkey
Ⅳ. 文档说明
# vim-testkey
Run your tests with a single keystroke! Tighten your TDD feedback loop!
Installation:
If you don't have a preferred installation method, I recommend
installing pathogen.vim, and
then simply copy and paste:
cd ~/.vim/bundle
git clone git://github.com/botandrose/vim-testkey.git
Usage:
- Hit enter in any test file to save and run it.
- Hit enter in any other file to save it and rerun the last test.
Built-in test type support:
- vspec via vim-flavor: files that end with
_spec.vim - rspec: files that end with
_spec.rb - cucumber: files that end with
.feature(runs scenario under the cursor only) - mocha: files that end with
_test.jsor_test.js.coffee
Adding or overriding test runner configuration:
Test runner configurations are added to the g:TestKey.runners dictionary. Each
test runner configuration is a dictionary with two keys: match and run.match is a regex for detecting the test type from the filename. run is a
function that returns a string to execute the test runner itself. This function
is provided two arguments: a:file and a:line, which are the current file
name and the current line number, respectively.
To add your own test runner, (or override an existing), just modify theg:TestKey.runners dictionary in your .vimrc. For example, here is a test
runner configuration for Cucumber:
let g:TestKey = { 'runners': {} }
let g:TestKey.runners.cucumber = { 'match': '.feature$' }
function g:TestKey.runners.cucumber.run(file, line)
return ':!clear && cucumber '.a:file.':'.a:line
endfunctionConfiguring the test key mapping
By default, <ENTER> is the test key. To use a different key, open up your
.vimrc, and prefill the g:TestKey configuration dictionary with testkey set
to your preferred test key. For example:
let g:TestKey = { 'testkey': '<leader>s' }Or, if you have already initialized the g:TestKey dictionary earlier, perhaps
to add a test runner:
let g:TestKey.testkey = '<leader>s'Acknowledgements
- Maureen Dugan: for pointing out the inadequacies of my previous setup.
- Gary Bernhardt: for the idea to use Enter as the test key.