Ruby, Rails, Web Development

Fun with Autotest & Growl

By Robert Pierce on February 22nd, 2008

pass.png pending.png fail.png

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).

image

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:

~/.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:

  1. Geoffrey Grosenbach for his excellent PeepCode screencasts that have helped me so much.
  2. 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

  1. RSpec Basics Peepcode Screencast (peepcode.com)
  2. Setting up autotest to use Growl (wincent.com)

Tags:

#

0 comments

Comments are closed

Content Tags

History

Copyright © 2008 Robert Pierce.

“Write a wise saying and your name will live forever.”
—Anonymous