Get a popup every time autotest runs your tests with the current result.
sudo gem install ZenTest sudo apt-get install libnotify-bin
.autotest
require 'autotest/redgreen'
module Autotest::Notify
def self.notify title, msg, img, pri='low', time=3000
`notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'`
end
Autotest.add_hook :ran_command do |autotest|
results = [autotest.results].flatten.join("\n")
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
folder = "~/Pictures/rails/"
if output =~ /[1-9]\d*\sfailures?/
notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 10000
elsif output =~ /[1-9]\d*\spending?/
notify "PENDING:", "#{output}", folder+"rails_pending.png", 'normal', 10000
else
notify "PASS:", "#{output}", folder+"rails_ok.png"
end
end
end
"
Icons for the messages can be found here and should go into your ~/Pictures/rails folder
Alternatively, one could use build-in pictures “gtk-dialog-error” / “gtk-dialog-info”…


5 comments
Comments feed for this article
May 14, 2008 at 14:18
Terry S
Thanks for this: most helpful.
I found that I was getting the red icon because the regexp was recognizing “0 failures” as indicating that there WERE failures, so I rewrote the regexp as follows to make it work:
[code]
if output =~ /([123456789]|[\d]{2,})\sfailures?/
notify "FAIL:", "#{output}", folder+"rails_fail.png", 'critical', 10000
[/code]
Hope it helps!
May 15, 2008 at 6:13
pragmatig
thanks, already fixed it in my working copy, but forgot to post the update, forgetful me :/
June 11, 2008 at 18:04
Evan
Excellent guide! Worked perfectly!
August 19, 2008 at 17:06
Ramblings » Blog Archive » autotest reminder (or why did it go boom?)
[...] Autotest RSpec Notifications for Ubuntu « My Pragmatig life Tags: autotest, gotchas, tips, zentest [...]
September 17, 2008 at 20:19
Spencer
Great article… very consise. I very recently moved from macOSX to Ubuntu, and I’ve been missing my Autotest + Growl setup. From what I’ve seen so far (I’ve only run a few tests with the new setup) it all works great!
Thanks for the code!