Over a million developers have joined DZone.

Modified Growl Support For Ruby Autotest

DZone's Guide to

Modified Growl Support For Ruby Autotest

Free Resource
# 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}"

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

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}