Autotest with growl

December 17th, 2007 Posted in Uncategorized

Here is my .autotest file. It’s based on John Nunemaker’s guide:

module Autotest::Growl
  IMAGE_ROOT = "~/.autotest_images" 

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

  Autotest.add_hook :green do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/\d+ examples, \d+ failures, \d+ pending/)
    growld "Pass", output, "#{IMAGE_ROOT}/pass.png"
  end

  Autotest.add_hook :red do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/\d+ examples, \d+ failures, \d+ pending/)
    growld "Fail", output, "#{IMAGE_ROOT}/fail.png"
  end

end

I had to change his code for a few reasons: first, the string regex didn’t match what I was getting in Rspec. Also, requiring ‘autotest/growl’ in the latest version of ZenTest (I’m on 3.6.1) adds an extraneous failure message before the :red hook fires off.

Post a Comment