Posted by ant
August 14th, 2007
Filed in Rails
I’ve just been getting autotest (part of the ZenTest suite) to work. It’s a really good framework for just getting your tests to run automatically in the background.
Following the instructions in one of the fantastic PeepCode screencasts I got the notifications from autotest to get piped though to Growl
In the PeepCode Episode there’s a link to to Wincent Colaiuta’s knowledge base on how to do this. However, it would seem that the formatting of the RSpec output has changed since this ~/.autotest file was written. “Not implemented” strings have changed to “Pending”
49 examples, 0 failures, 1 pending
I’ve rewritten the file and you can find it below. I also extended it slightly as I wanted to see when tests were pending. Now if there are no failures, but there are pending descriptions they will be flagged up with a different icon so you know theres some tests to be implemented.
require 'autotest/redgreen'
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|
results = [autotest.results].flatten.join("\n")
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
if output =~ /[1-9]\sfailures?/
growl "FAIL:", "#{output}", "~/Library/autotest/rails_fail.png", 2, "-s"
elsif output =~ /[1-9]\spending?/
growl "PENDING:", "#{output}", "~/Library/autotest/rails_pending.png", 2, "-s"
else
growl "PASS:", "#{output}", "~/Library/autotest/rails_ok.png"
end
end
end
2 Responses to “Autotest, RSpec and Growl on OS X”
Leave a Reply ☆
Blog uses Mephisto
Design from OSWD
by dreamLogic

March 20th, 2008 at 04:42 PM
Thanks for the script update! Do you have the rails_pending.png for download?
-Joe
April 15th, 2008 at 03:00 PM
i converted it to ubuntu: http://pragmatig.wordpress.com/2008/04/15/autotest-rspec-notifications-for-ubuntu/