a step-by-step guide to establishing a BDD rails environment for your Mac
If you're a rails developer and you've been contemplating making the move to behavior driven development with rails, this will be a good place for you to start. Below you will find all the major steps necessary to get your Mac rails development environment all tricked out for BDD, including the much-enjoyed growl notifications. In addition to the fundamentals, (rspec, rspec_on_rails), it's highly reccomended that you install and configure a variety of supporting software applications (zentest, growl). What follows will get you up and running -- how you customize further, is up to you.
This tutorial assumes that you have a particular rails project that you are working with. I'll refer to this project as yourproject>. Some commands will need to be executed from your project root, while others will need to be run from your home directory -- which I'll refer to as yourcomputer>. Still, other commands may be entered from any directory you find yourself in. Please be aware of which directory you are in when copy commands out of this tutorial, this will save you some headaches.
Install the rspec plugin
It's also possible to install the rspec gem, but I like to use plugins. see here for more information about rspec installation.
yourproject> ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
Install rspec_on_rails plugin
see here for more information about rspec_on_rails installation.
yourproject> ruby script/plugin install ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails
Install ZenTest gem
You will need to install the ZenTest gem.
yourcomputer>sudo gem install ZenTest
see more information on zentestInstall and configure growl (and growlnotify)
-
download and install Growl from http://growl.info/
- NOTE: While configuring growl, make sure that the check-box labeled 'hide all notifications' is NOT checked. (!)
- Install growlnotify
Your installation of Growl will give you some extras, one of these extras is called growlnotify. Install this in the following manner:
yourcomputer>cd /Volumes/Growl 1.1.2/Extras/growlnotify/ yourcomputer>sudo sh install.sh
The version numbers shown may be different, to find out where your growlnotify is located, do the following:
yourcomputer>locate growlnotify
-
Install redgreen gem
In all honesty, I'm not sure if you really need to install this or not, I've read conflicting accounts, so, I'm not sure. I've installed redgreen and it certainly doesn't hurt anything.
yourcomputer>sudo gem install redgreen
Configure autotest to work with growlnotify
- in your home (~) directory create a hidden file named .autotest (note the dot).
yourcomputer> vi .autotest
copy the following code and paste it into your .autotest file: (this code has been copied from http://blog.internautdesign.com/2006/11/12/autotest-growl-goodness ) and slightly modified by me.
module Autotest::Growl def self.growl title, msg, img, pri=0, sticky="" system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" end Autotest.add_hook :ran_command do |at| results = [at.results].flatten.join("\n") output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) if output if $~[2].to_i > 0 growl "Test Results", "#{output}", "~/Library/autotest/rails_fail.png", 2 else growl "Test Results", "#{output}", "~/Library/autotest/rails_ok.png" end end end end- In your ~/Library directory, create a directory called autotest
yourcomputer> cd ~/Library yourcomputer> mkdir autotest
- Add these images to the new autotest directory that you have just created.
- in your home (~) directory create a hidden file named .autotest (note the dot).
start autotest
yourproject> autotest -railsgenerate your rspec and application scaffolding
yourproject>ruby script/generate rspec- At this point, all your spec test results should appear as growl notifications! I'll be publishing more articles about how to use rspec with rails, so stay tuned.
more resources
- http://rspec.rubyforge.org/documentation/rails/install.html
- http://www.zenspider.com/ZSS/Products/ZenTest/
- http://www.growl.info/
- http://peepcode.com/
- http://rspec.rubyforge.org/documentation/index.html