Autotest Growl Notifications

March 23, 2009

I recently have had to set this up on another machine so here is a little guide which might help you if you want to setup growl notification of autotest results.

  • Make sure growl is installed
  • Make sure growlnotify is installed you will find it in the Extras directory of the Growl dmg (copy growlnotify to /usr/local/bin to test this open a terminal and type growlnotify)
  • Add the following to a file called ~/.autotest
require 'autotest/redgreen'
  require 'autotest/timestamp'

  module Autotest::Growl

    def self.growl(title, msg, img, pri=0, sticky="")
      system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" 
    end

    Autotest.add_hook :ran_command do |at|
      image_root = "~/.autotest_images" 
      results = [at.results].flatten.join("\n")
      output = results.slice(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/)
      if output
        if $~[3].to_i > 0 || $~[4].to_i > 0
          growl "FAIL", "#{output}", "#{image_root}/fail.png", 2
        else
          growl "Pass", "#{output}", "#{image_root}/pass.png" 
        end
      end
    end

  end

Extract this file to ~/.autotest_images directory.

You are now good to go!