Getting notifications of autotest results on Linux (Gnome)

If you watched the PeepCode episode about RSpec (the first of the trilogy), you may want something like growl on linux to get informed about the results of autotest. Well, there is such thing, but it is quite complicated.

You can use libnotify on Gnome, though. Those little alerts Ubuntu shows you (3 new updates, It’s time to restart your computer, Connected to Wireless Network etc), all uses libnotify. Let’s move on!

1) Install the libnotify-bin package via apt-get

2) Go to a terminal and type, remembering to change ZenTest-3.6.0 to your current version.

sudo gedit /usr/lib/ruby/gems/1.8/gems/ZenTest-3.6.0/lib/autotest/gnomenotify.rb

3) Paste the following on the new file

# -*- ruby -*-
# Adapted from PeepCode RSpec screencast no 1, 
# who got it from someone else!
# Adapted with tip from http://ph7spot.com/articles/getting_started_with_autotest
# by DitoCujo (https://ditoinfo.wordpress.com)
module Autotest::GnomeNotify
  EXPIRATION_IN_SECONDS = 5
  ERROR_ICON = "gtk-dialog-error"
  SUCCESS_ICON = "gtk-dialog-info"
  def self.notify(title, msg, icon)
    options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{icon}"
    system "notify-send #{options} '#{title}' '#{msg}'"
  end
  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
    if output
      if $~[2].to_i > 0
        notify "FAIL", "#{output}", ERROR_ICON
      else
        notify "Success!", "#{output}", SUCCESS_ICON
      end
    end
  end
end

4) Now save the file and open your .autotest file (/home/_____/.autotest – Create one if it does not exist) and require the file you just created by placing this line on the top:

require ‘autotest/gnomenotify’

Done! You should now get beautiful notifications on your screen like this one here

Gnome Notify for Autotest

~ by Dante Regis on August 22, 2007.

6 Responses to “Getting notifications of autotest results on Linux (Gnome)”

  1. hey there – do you mean /var/lib/gem…/Zen… instead of /usr/

  2. Well, this path I’ve placed is valid for Ubuntu, downloading ruby-gems from source on their website. Which distro are you using, there, glenn?

  3. I have a rather stream-of-consciousness howto via the native ruby wrappers in ruby-libnotify with the necessary hook code to do some more sophisticated stuff like customize the icon and attach the notification to a system tray icon here: http://dcberner.blogspot.com/2007/10/ruby-libnotify.html

  4. […] Which I’m not familiar with, but assume it’s for propeller-heads like me.🙂 Here’s a neat trick to display any message you choose in a pop-up. Looks like they use it to get […]

  5. The code supplied contains syntax errors in line 15! The closing bracket is missing and the quotation marks will not be understood by the ruby interpreter…

  6. On Ubuntu 10.10 it will hang the terminal after it runs.
    I through an exit in and your back at the prompt.

    else
    notify “Success!”, “#{output}”, SUCCESS_ICON
    end
    exit()
    end
    end
    end

    this worked for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: