Run Rspec specs from Vim
Vim script AppleScript Ruby
Clone or download
dgmstuart and gylaz Backfill test cases depending on current file
Add some missing test cases and remove some superfluous ones:

  1. Remove references to last_spec_line
  2. Add a Spec for RunCurrentSpecFile when in a spec file
  3. Spec for RunNearestSpec when in a spec file
  4. Test that RunAllSpecs runs all specs

Detail:

1. Remove references to last_spec_line

The test for RunCurrentSpecFile included references to a variable
'last_spec_line', and two contexts to handle the case where it is set or
not set.

This variable seems to have never been referenced in the code. It looks
like it was introduced in 6a39ba7, but only in the specs. My guess is
that this was used in a previous attempted implementation of that PR
(#79) and committed by
mistake.

2. Add a Spec for RunCurrentSpecFile when in a spec file

Approach: Create a new buffer and name it differently to the last_spec_file

:bdelete! is used in the after block (as opposed to e.g. :close!) so
that the buffer is actually deleted and new buffers can be created with
the same name in other tests.

Note: previously only the fallback case (calling RunCurrentSpecFile when
not currently in a spec file) was covered by specs.

3. Spec for RunNearestSpec when in a spec file

Approach:
- Set up a spec buffer with a different file name to last_spec_file and
  last_spec_file_with_line
- Write some lines into that buffer
- Jump to some point in the middle of that file

4. Test that RunAllSpecs runs all specs

Previously there was no test case for this.

Approach: regardless of anything else which might be set (e.g.
last_spec) this always runs 'spec'

NOTE: we need to explicitly set g:rspec_command when asserting the
resulting command, because by default the command differs depending on
environment - e.g. the default terminal command first calls 'clear' in
the terminal.
Latest commit 52a7259 Jan 21, 2017

README.md

rspec.vim

This is a lightweight RSpec runner for Vim and MacVim.

Installation

Recommended installation with vundle:

Plugin 'thoughtbot/vim-rspec'

If using zsh on OS X it may be necessary to move /etc/zshenv to /etc/zshrc.

Configuration

Key mappings

Add your preferred key mappings to your .vimrc file.

" RSpec.vim mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>

Custom command

Overwrite the g:rspec_command variable to execute a custom command.

Example:

let g:rspec_command = "!rspec --drb {spec}"

This g:rspec_command variable can be used to support any number of test runners or pre-loaders. For example, to use Dispatch:

let g:rspec_command = "Dispatch rspec {spec}"

Or, Dispatch and Zeus together:

let g:rspec_command = "compiler rspec | set makeprg=zeus | Make rspec {spec}"

Custom runners

Overwrite the g:rspec_runner variable to set a custom launch script. At the moment there are two MacVim-specific runners, i.e. os_x_terminal and os_x_iterm. The default is os_x_terminal, but you can set this to anything you want, provided you include the appropriate script inside the plugin's bin/ directory.

iTerm instead of Terminal

If you use iTerm, you can set g:rspec_runner to use the included iterm launching script. This will run the specs in the last session of the current terminal.

let g:rspec_runner = "os_x_iterm"

If you use the iTerm2 nightlies, the os_x_iterm runner will not work (due to AppleScript incompatibilities between the old and new versions of iTerm2).

Instead use the os_x_iterm2 runner, configure it like so:

let g:rspec_runner = "os_x_iterm2"

Running tests

Tests are written using vim-vspec and run with vim-flavor.

Install the vim-flavor gem, install the dependencies and run the tests:

gem install vim-flavor
vim-flavor install
rake

Credits

thoughtbot

rspec.vim is maintained by thoughtbot's Vim enthusiasts and contributors like you. Thank you!

It was strongly influenced by Gary Bernhardt's Destroy All Software screencasts.

License

rspec.vim is copyright © 2016 thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.

The names and logos for thoughtbot are trademarks of thoughtbot, inc.