Rspec Quickfix Formatter

Provides a rspec formatter that outputs a file vim’s quickfix feature will understand. This allows nice integration between rspec test failures and the vim editor.

Requirements

rspec 1.3.X vim 7.X

I haven’t tried using this with rspec 2 yet.

Install

There are two parts to this install: 1) Setting up rspec to use the formatter and write a file in the quickfix format, and 2) setting up vim to read from the quickfix file.

Setting up rspec

There are a couple different ways to achieve this. I prefer the first option, but the others should work too.

configure with spec.opts

Add the following lines to your spec.opts file:

–require rspec-quickfix-formatter –format Spec::Runner::Formatter::QuickfixFormatter:tmp/quickfix

The path passed to –format will be the location that the quickfix file will be written to disk. I always run my specs from the projects root directory (which always has tmp directories), so the setting of tmp/quickfix works well for me. This path will need to match the path in your vim configuration.

configure in spec_helper.rb

configure using spec command line options

Setting up vim

There are two aspects to configuring vim, defining the error format, and loading the file into the quickfix window.

Use this command to set vim’s error format:

:set errorformat=%f:%l\ %n\ %m

Use this command to open the quickfix file:

:cfile tmp/quickfix

Or create a shortcut:

map <leader>s :cfile tmp/quickfix<CR>

The tmp/quickfix needs to be the path to your quickfix file. Since I start vim in the root of my project, a relative path works well for me.

For more information about the quickfix and related location list features in vim, see:

:help quickfix

TODO: it may be possible to leverage the default errorformat instead of configuring a simple one.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Andy Hartford. See LICENSE for details.