Report abuse


			
#!/usr/bin/env ruby
# Symlink this to ~/.autotest
require 'autotest/redgreen'

AUTOTEST_IMAGE_PATH = File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : File.expand_path(__FILE__))

module Autotest::Growl
  def self.growl title, msg, img, pri=0, stick=""
    system "growlnotify --image #{img.inspect} -p #{pri} -m #{msg.inspect} #{title.inspect} #{stick}"
  end

  Autotest.add_hook :ran_command do |autotest|
    filtered = autotest.results.grep(/\d+\s.*tests?/)
    if filtered.empty?
      output = ""
      title = "No tests found"
    else
      output = filtered.last.slice(/\s(\d+)\s.*assertions?,\s(\d+)\s.*failures?,\s(\d+)\s.*errors?/).strip
      title = "#{filtered.last.slice(/(\d+)\s.*tests?/).strip} run"
    end

    if output =~ /[1-9]\serrors?/
      growl "#{title}", "#{output}", "#{AUTOTEST_IMAGE_PATH}/fail.jpg", +2, "--sticky"
    elsif output =~ /[1-9]\sfailures?/
      growl "#{title}", "#{output}", "#{AUTOTEST_IMAGE_PATH}/pending.jpg", +1
    else
      growl "#{title}", "#{output}", "#{AUTOTEST_IMAGE_PATH}/ok.jpg", -2
    end
  end
end

Autotest.add_hook :initialize do |at|
  %w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)}
end