Posted on January 5, 2006 at 6:40 pm

So, you’re developing Ruby on Rails apps on your shiny Mac and you want to get Growl notifications when your rake tasks are complete. Below, I will illustrate a fairly simple way to get Growl notifications when the test_units and test_functional tasks are complete. This method can be easily extended to any of the other tasks as well.

Prerequisites

  • Growl is installed and running.
  • The RubyCocoa framework is installed.
  • You also need a copy of the Ruby binding from the Growl source distribution. Go to the Growl Developer Downloads page and download the latest tarball or bzball. Extract the files and grab a copy of Growl.rb from the Bindings/ruby directory.

Integration with Rails

First, copy the Growl.rb file that you extracted from the Growl source into your Rails application’s lib directory. Name it growl.rb (all lowercase).

Next, create a new file called growl_notifications.rake in your Rails application’s lib/tasks directory. Copy and paste the following code into this file:

task :test_units do
  task_notifier 'Rake Task', 'Unit testing has completed.'
end

task :test_functional do |t|
  task_notifier 'Rake Task', 'Functional testing has completed.'
end

def task_notifier(title, message)
  begin
    require 'growl'
    n = GrowlNotifier.new('Rake',['RakeTask'],nil)
    n.register()
    n.notify('RakeTask', title, message)
  rescue
  end
end

Growl’s Ruby bindings allow you, among other things, to customize the icon that is displayed in the notification. Take a peek inside the growl.rb file for details.

I would like to extend this further to show the results from the tests in the notification message body. The results are part of a TestResult object, but I’m not sure if there is a way to get at this object by the time I create the notification. If you how I can do this, please let me know!

2 Comments:
Posted on January 9, 2006 at 11:22 pm by Plaid

I suspect I how you can do it.

Spin on the TestResult object until present with an until(object) or similar, then output results once the object is populated.

Keep in mind, I don’t know Ruby, I’m just extrapolating from other languages.

Posted on January 10, 2006 at 12:51 pm by Admin

I don’t know of a way to get a hold of the TestResult instance. Also, no notification goes out if any of the tests fail.

Leave a comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>