Diligent Designer
Passionate Pixel Pushing
Ruby, Rails, Web Development
Fun with Autotest & Growl
So tonight I was about halfway into Geoffrey Grosenbach’s RSpec Mocks and Models screencast and remembered that I had run into a roadblock the other night trying to get autotest to run correctly. I couldn’t very well be attempting BDD without a functioning autotest. And of course I couldn’t very run autotest without implementing growl notifications. And of course I couldn’t implement growl notifications without making some cool graphics that would make me happy every time I saw them.
So, being the “leans-more-toward-designer-than-developer” kind of developer that I am—here I am two three four hours later, having a ball, but not much closer to really getting my mind wrapped around RSpec and BDD. I did finally get autotest and the growl notifications working and enjoyed a fun little Photoshop diversion—plus I got some time in on my new publishing platform (still tweaking styles and layout of my Mephisto blog theme).
I’ve recently committed to trying to give back a little to the ruby/rails online community that has helped me so much over the years. So I decided to take the time to put the files up tonight (along with the code I found worked for me, and a simple screencast so you can see them in action). Maybe someone will find these useful and perhaps even enjoy their development a tiny bit more.
Download Brief Screencast
FunwithAutotestandGrowl_Fnl.mov (9mb Quicktime File)
Graphic files:
- pass.png
- pending.png
- fail.png
- AutoestGrowlButtons.psd.zip (Photoshop source file)
~/.autotest listing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
require 'autotest/redgreen' require 'autotest/timestamp' module Autotest::Growl def self.growl title, msg, img, pri=0, stick="" system "growlnotify -n autotest --image #{img} -p #{pri} -m #{ msg.inspect} #{title} #{stick}" end Autotest.add_hook :ran_command do |autotest| output = autotest.results.grep(/\d+\s.*examples?/).last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?(?:,\s(\d+)\s.*pending)?/) # if output =~ /[1-9]\sfailures?/ if output =~ /[1-9][0-9]?\sfailure/ growl "Test Results", "#{output}", "~/Library/autotest/fail.png", 2, "-s" elsif output =~ /pending/ growl "Test Results", "#{output}", "~/Library/autotest/pending.png" else growl "Test Results", "#{output}", "~/Library/autotest/pass.png" end end end |
Lessons Learned
The problem I had with getting autotest to work had to do with version conflicts between zentest and rspec. Just be aware that it can potentially exist and Google your way through it. I can’t even remember how or what I changed anymore to get it working, but I am using the following versions successfully as of this writing: rspec (1.1.3), ZenTest (3.9.1), rails (2.0.2).
Acknowledgements:
- Geoffrey Grosenbach for his excellent PeepCode screencasts that have helped me so much.
- James Deville for the writeup and code that worked for me and my setup. (Be sure to read Eric Wollesen’s comment with an update to the regex.)
Reference
- RSpec Basics Peepcode Screencast (peepcode.com)
- Setting up autotest to use Growl (wincent.com)