Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Modified Growl support for Ruby autotest

# This code is a different approach to using Growl notifications (Mac OS X)
# with autotest for Ruby.
# The code can be added to ~/.autotest
# Be sure to comment out "require 'autotest/growl'" if you have that line
# in your .autotest file.
# Based on ZenTest-3.6.1/lib/autotest/growl.rb
# Requires the 2 rails png graphics found at:
# http://blog.internautdesign.com/2006/11/12/autotest-growl-goodness

module Autotest::Growl
  # save the name of the working directory (e.g., the app name)
  # to be used as a key to identify this particular run of autotest
  # so the same growl notification will be reused for updates,
  # instead of a new growl window for every posting.
  @@current_directory_name = Dir.pwd.match(/([^\/]+)\z/).to_s
  def self.growl title, msg, pri=0
    title += " in #{@@current_directory_name}"
    msg += " at #{Time.now}"
    # ### change the path to the directory for the png graphics:
    system "growlnotify -n autotest #{pri > 0 ? '-s ' : ''}--image /Users/grant/Pictures/rails_#{pri > 0 ? 'fail' : 'ok'}.png -p #{pri} -d '#{Dir.pwd}' -m #{msg.inspect} #{title}"
  end

  Autotest.add_hook :run do  |at|
    growl "autotest running", "Started"
  end
  Autotest.add_hook :red do |at|
    growl "Tests Failed", "#{at.files_to_test.size} tests failed", 2
  end
  Autotest.add_hook :green do |at|
    growl "Tests Passed", "Tests passed", -2 if at.tainted
  end
  Autotest.add_hook :all_good do |at|
    growl "Tests Passed", "All tests passed", -2 if at.tainted
  end
end

.autotest file

require 'autotest/redgreen'
require 'autotest/timestamp'
#require 'autotest/growl'

#require 'autotest/html_report'
#require 'autotest/kdenotify'
#require 'autotest/menu'
#require 'autotest/pretty'
#require 'autotest/snarl'

# Sort-of from http://blog.labratz.net/articles/2006/09/13/growl-autotest-rails-with-zentest-3-4-0
def growl(title, msg, pri=0, stick="", image="")
  image_arg = (!image.empty?) ? "--image #{image}" : ""
  system "growlnotify -n autotest #{image_arg} -p #{pri} -m #{msg.inspect} #{title} #{stick}" 
end

Autotest.add_hook :red do |at|
  growl("Tests Failed", "#{at.files_to_test.size} tests failed", 2, "", "/Applications/Mail.app/Contents/Resources/Caution.tiff")
end

Autotest.add_hook :green do |at|
  growl("Tests Passed", "All tests passed", -2, "", "/Applications/Mail.app/Contents/Resources/certificate.tiff") #if at.tainted
end  
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS