Updating RSpec/Autotest/Growl

If you’ve followed the instructions over at Daniel Fischer’s to get setup with the latest version of RSpec, Autotest, and Growl, you must have noticed something was missing.

Apparently that article was written before ‘not implemented’ support was added to RSpec. Well, it’s super easy to extend the code to support this. First, make sure you follow Mr. Fischer’s instructions.

Then, edit your ~/.autotest file to read:

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.last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?,\s(\d+)\s.*not implemented/)
    if output =~ /[1-9]\sfailures?/
      growl "Test Results", "#{output}", "~/Library/autotest/rails_fail.png", 2, "-s" 
          elsif output =~ /[1-9]\snot implemented/
      growl "Test Results", "#{output}", "~/Library/autotest/rails_not_impl.png", 2, "-s" 
    else
      growl "Test Results", "#{output}", "~/Library/autotest/rails_ok.png" 
    end
  end
end

And then add this third image to your ~/Library/autotest folder:

With the final result looking like this: