⇐ Previous | Next ⇒

Running Rspec from Vim

Post created 2013-11-27 22:02 by Gabe Koss.

When working on Rspec tests for Ruby code it is often useful to run the tests many times.

Basic Commands

Run all spec tests with :!rspec. That is helpful but sometimes you want to be a little more finite.

Run rspec on current file

:!rspec %

Run rspec on current line

:exe "!rspec % -l " . line('.')

Run rspec tests that match current word

:exe "!rspec %  -e " . expand("<cword>")

Binding with leader

These commands are pretty useful but typing them into the command line can be laborious. For maximum efficiency add them to your .vimrc or .vim.custom files.

This binds the following:

map \f :w\|!rspec %<cr>
map \l :w\|:exe "!rspec % -l " . line('.')<cr>
map \w :w\|:exe "!rspec %  -e " . expand("<cword>")<cr>

This was originally a github gist

comments powered by Disqus