Training

Do you want to quickly get going with tdd in ruby? Here is the simplest rundown to get a working effective tool stack that will help you start coding more effectively in a test driven fashion in your ruby environment. I am not even discussing rails here at the moment, along with all of the tools that it brings to the table for testing. Just core ruby.

Basic Requirements

For this post I am assuming an osx based environment, mostly for the growl ability. All of the other tools that are mentioned will work without issue on a regular unix based environment (I have not tried this stuff on the windows platform yet):

Growl - install this so that you will later on be able to use growl notifications (think toast windows).

RVM - Ruby Virtual Machine. This is a great tools to keep you base ruby installation completely clean, as well as be able to install/test multiple versions of ruby against your application. You don't need to install this, but I would strongly recommend it.

Gems

Assuming an installed ruby version of 1.8.7, here are the steps from the command line:

gem install rspec

gem install autotest

gem install autotest-growl

gem install autotest-fsevent

That's about it for the gems you need to install. Autotest is a tool that you can use to monitor your working folder in the background and it will automatically rerun the accompanying tests if there are changes to any of the items under lib/specs directory. RSpec has a thin wrapper around autotest called autospec. It has a default convention that it uses to monitor for file changes in your application. With the default convention, you just need to make sure that:

your test code lives under a folder named spec

your production code is in the lib folder

The last pieces of the puzzle is to hook into autotest to do the growl notification. I created a folder under my devtools folder named spec_growl add a simple .autotest file to your root directory that contains a couple of hooks into the AutoTest, I took a script that I found at this location and just modified it slightly.