So I’ve finally gotten myself a mac. Well, actually my boss got one for me, but you get the point. Anyways, my coworkers and I were having problems with Autotest, RSpec, and Growl before the recent release. However, since 1.0.8 is a new version, we decided to try again. So far it’s worked. So with a big thanks to Daniel Fischer, I’d like to write up how.
How-to
Here’s how. First, get your essentials:
- Growl
- growlnotify
- Zentest
- Rspec
Second, download the following pictures:



Third, copy the following into your .autotest file:
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?/
growl "Test Results", "#{output}", "~/Library/autotest/rails_fail.png", 2, "-s"
elsif output =~ /pending/
growl "Test Results", "#{output}", "~/Library/autotest/rails_pending.png"
else
growl "Test Results", "#{output}", "~/Library/autotest/rails_ok.png"
end
end
end
If you don’t already have one. Just save it to ~/.autotest. Replace the three image locations with your downloaded ones, and you should be good to go!
Steve | 21-Sep-07 at 6:45 pm | Permalink
Hey, I just read your article but have been having difficulty in getting everything working together. When I try to run ‘autotest’, I get this error:
loading rspec_rails_autotest
spec –diff unified spec/models/weather_spec.rb spec/controllers/weathers_contro
ller_spec.rb
c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:144:in `open’: Exec
format error - spec –diff unified spec/models/weather_spec.rb spec/controller
s/weathers_controller_spec.rb (Errno::ENOEXEC)
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:144:in
`run_tests’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:127:in
`get_to_green’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:107:in
`run’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:105:in
`loop’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:105:in
`run’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/lib/autotest.rb:63:in
`run’
from c:/ruby/lib/ruby/gems/1.8/gems/zentest-3.5.0/bin/autotest:36
from c:/ruby/bin/autotest:16:in `load’
from c:/ruby/bin/autotest:16
–If you can help in any way, i’d greatly appreciate it! Thanks!
James Deville | 21-Sep-07 at 7:35 pm | Permalink
My first guess would be updating ZenTest. I believe there was a update to ZenTest that made it work better with RSpec.
JD
Lance Carlson | 23-Sep-07 at 10:57 am | Permalink
I don’t understand why you use msg.inspect. What does that do as opposed to just printing msg?
James Deville | 23-Sep-07 at 11:53 am | Permalink
That would be due to me copying the initial version of that script from Daniel (link in article). I imagine the only real reason is to ensure that the message gets turned into a full string as follows:
vs:
Lance Carlson | 25-Sep-07 at 8:42 am | Permalink
That’s a good reason! I responded to your comment on my blog btw. Also just doing #{msg} worked fine for me.
Lance Carlson | 25-Sep-07 at 8:43 am | Permalink
Wait, I looked at your code example again.. wouldn’t that mean inspect is not what you’re looking for?
Eric Wollesen | 24-Nov-07 at 1:00 am | Permalink
You have a bug in your .autotest file. I had a case where I had 11 examples, and 10 failures, yet autotest showed the success image. Here’s a new .autotest, note the slightly modified regexp for checking for failures.
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][0-9]?\sfailures/
growl “Test Results”, “#{output}”, “~/Library/autotest/rails_fail.png”, 2 #, “-s”
elsif output =~ /pending/
growl “Test Results”, “#{output}”, “~/Library/autotest/rails_pending.png”
else
growl “Test Results”, “#{output}”, “~/Library/autotest/rails_ok.png”
end
end
end
Eric Wollesen | 24-Nov-07 at 1:23 am | Permalink
Whoops, I typo’d in my previous post. The line:
if output =~ /[1-9][0-9]?\sfailures/
should read
if output =~ /[1-9][0-9]?\sfailure/
Sorry about that.
Jeremy Weiland | 01-Feb-08 at 11:24 pm | Permalink
Thanks, this helped a lot. I like having a persistent reminder that pending specs have not been written.