Wednesday, January 24, 2007

Autotest/Gnome Eye Candy

Make sure you have notify-send installed. On Ubuntu just run:


sudo apt-get install libnotify-bin

Now edit your ~/.autotest and insert following:


require 'autotest/redgreen'
require 'autotest/timestamp'

module Autotest::Notify
  def self.notify(title, message, priority='critical')
    icon = if priority == 'critical'
      'dialog-error'
    else
      'dialog-information'
    end
    system "notify-send -u #{priority} -t 10000 -i #{icon} '#{title}' '#{message.inspect}'"
  end

  Autotest.add_hook :red do |at|
    tests = 0
    assertions = 0
    failures = 0
    errors = 0
    at.results.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/) do |t, a, f, e|
      tests += t.to_i
      assertions += a.to_i
      failures += f.to_i
      errors += e.to_i
    end
    message = "%d tests, %d assertions, %d failures, %d errors" % 
      [tests, assertions, failures, errors]
    notify("Tests Failed", message)
  end

  Autotest.add_hook :green do |at|
    notify("Tests Passed", "Outstanding tests passed", 'low') if at.tainted
  end

  Autotest.add_hook :all do |at|_hook
    notify("autotest", "Tests have fully passed", 'low')
  end
end

You will get pretty test summary notifications after each save.

3 comments:

S. Potter said...

Good stuff, but this script now doesn't work for RSpec 1.x. Check out my blog entry for the updated .autotest file contents:
http://snakesgemscoffee.blogspot.com/2007/07/marrying-autotest-with-rspec-on-gnome.html

Derek Berner said...

I've got a pure-ruby approach here: http://dcberner.blogspot.com/2007/10/ruby-libnotify.html

It lets you do some fun stuff like attach it to a system tray icon.

Derek said...

My blog has moved.

http://devblog.bernerbits.com/?p=31