Subscribe to RSS Feed

Elijah Miller

06 Feb 2009

TextMate, Rspec and Dot Spec Party

I’m going to show you how to get a great looking RSpec runner window and not go insane while trying to use it.

Beautiful passing green specs, easy to read failing red specs, a clickable backtrace and the failing spec block for good measure.

Pretty sweet right? Let’s get started.

Install RSpec bundle

mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles/
git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'

And now the fun begins

  1. First you press Shift-Control-Option R (⇧⌃⌥R) to select the RSpec Bundle. This is so easy it only takes two hands.
  2. Now we need to press Command 3 (⌘3) to select the RSpec Bundle out of the list.
  3. Command R (⌘R) to run the spec or Shift Command R (⇧⌘R) to run an individual spec.
  4. Party time!

The party's over

The next time you open a spec or regular Ruby file you’ll be started in the mode you last forced. That means you’ll probably have to learn to do that tedious keyboard finger dance quite often.

[Audio] "This shit's getting way too complicated for me." - Barack Obama

We could switch the Ruby and RSpec shortcuts to a simpler keystroke, that would alleviate most of the problem. Except we would still need to press some keystroke to force the mode upon opening a new file.

Running specs needs to be dead simple so people actually do it!

Dot spec has invited you to a party!

There’s a far easier way to solve this problem. Just rename all your spec files to .spec and you will only have to tell TextMate one time to use RSpec mode and it will remember forever!

The steps after switching to dot spec:

  1. Command R (⌘R) to run the spec or Shift Command R (⇧⌘R) to run an individual spec.
  2. Party Time!

You've also been invited to a pre-party!

Who has time to rename all those files? Definitely not you!

There is also a fancy converter for renaming all of your old specs!

# in your project dir
gem install thor &&
thor install \
https://github.com/jqr/thor_tasks/raw/master/rspec_rename_to_dotspec.thor &&
thor rspec:rename_to_dotspec