Tuesday, July 7, 2009

Vim Plugin for Ruby Testing

If you're using ruby and you're using vim, you've probably noticed some awesome tools out there (mostly created by Tim Pope). You've got rails.vim, ruby.vim, etc. However, I noticed that there was a lack of support for some features that Textmate users have been taking for granted for a long time. I'm talking about the support Textmate provides around running your tests.

The key features I was missing from Textmate were having text output in a new buffer, the ability to run a focused test (the test my cursor was currently on) and the ability to run all tests in a given context. With the help of some ThoughtWorks colleagues on a previous project, I've put together a vim plugin that I think meets these needs.

The plugin is ruby_focused_unit_test_vim. The plugin currently supports the following ruby testing tools:

- test/unit
- rspec
- shoulda
- dust

The current features the plugin supports are:

- run focused test
- run focused context
- run entire test file
- all commands stream output to a new buffer

The streaming feature is very cool (thanks to David Vollbracht). It gives you instant feedback as your tests pass/fail in a new buffer. It feels very similar to the test output in Textmate.

The installation process is simple. Just clone the git repo and copy the ruby_focused_unit_test.vim file into your .vim/plugin directory.



Once you've installed the plugin, three commands become available to you:

- RunRubyFocusedUnitTest
- RunRubyFocusedContext
- RunAllRubyTests

To make things simple, I map these commands in my .vimrc:



I hope you find the plugin useful. In the future I'll write about my overall vim setup for ruby/rails development.

0 comments: