Gnome and Autospec Notifications
I’m very keen on DBB with RSpec now and I wanted to share how I set up autospec notifications on Ubuntu (Jaunty 9.04) as long as the post I followed to do it is no longer available.
I’m using XCFE but should work perfectly on Gnome as well. This is an screenshot of what you’ll get in the end:

autospec notification XFCE/Gnome
First you need the ZenTest gem, you probably already do:
$ sudo gem install ZenTest $ sudo gem install redgreen
Then install the libnotify-bin package:
$ sudo apt-get install libnotify-bin
Here is the trick. Create a file called ~/.autotest with this:
#!/bin/ruby require 'redgreen' require 'autotest/timestamp' module Autotest::GnomeNotify def self.notify title, msg, img system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000" end Autotest.add_hook :ran_command do |at| image_root = "~/.autotest_images" results = [at.results].flatten.join("\n") results.gsub!(/\\e\[\d+m/,'') output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?/) puts output.inspect if output if $~[2].to_i > 0 notify "FAIL", "#{output}", "#{image_root}/fail.png" else notify "Pass", "#{output}", "#{image_root}/pass.png" end end end end
As you can see I use the fail.png and pass.png images to show those cheesy smileys : ). You can download them here and copy them to ~/.autotest_images/.
Make your tests go green and have a beer! : )
Update: Added redgreen gem and changed “require redgreen” as Rodrigo Flores and rakk suggested. Thanks!
Update: Changed mistakenly escaped >. Thanks to Martin y Hunter for the comments.
English
Español
Rodrigo Flores
21 Aug, 2009
You need to install the redgreen gem also. The file .autotest only work if instead of “autotest/redgreen”, you put “redgreen/autotest”.
Thanks for the hints
admin
21 Aug, 2009
Hi Rodrigo,
Thanks for the comment. I don’t have any gem called ‘redgreen’ installed. It seems to come with Zentest:
I can also do this:
Maybe we have a version mismatch.
rakk
22 Aug, 2009
sudo gem install redgreen
- require ‘autotest/redgreen’
+ require ‘redgreen’
for ZenTest (4.1.4)
admin
22 Aug, 2009
Right rakk! I had ZenTest 4.0.0. Updating the post now.
Jesse
15 Dec, 2009
I couldn’t find the images in the zip file. here is a link to a page with red and green smiley faces. http://getsatisfaction.com/railstutorial/topics/gnome_and_autospec
admin
15 Dec, 2009
Hi Jesse. The images should be inside a hidden directory called “.autotest_images”. Maybe you missed them because the dir is hidden.
Martin
23 Apr, 2010
I am quite new to rails, did exactly what you did, but neither autotest nor autospec opens the graphical display. Autotest reacts to changes on the file system as expected, but still, no gui. I have gnome and
autotest-rails (4.1.0)
redgreen (1.2.2)
rspec (1.3.0)
rspec-rails (1.3.2, 1.3.0)
ZenTest (4.3.1)
any idea? Thx a lot.
Martin
23 Apr, 2010
ah, something else: it says
./.autotest:17: warning: `&’ interpreted as argument prefix
./.autotest:17: warning: unused literal ignored
thx again
Hunter
26 Apr, 2010
Martin:
I had the same problem, but I got it working by replacing the “>” on line 17 with a >
Hunter
26 Apr, 2010
Martin:
What I meant to say was I fixed it by replacing the “& g t” on line 17 with a >. (As my previous post demonstrated, “& g t” is the character entity for >)
Jonathon Jones
2 May, 2010
I can confirm that Hunter’s solution of replacing & g t with > works to fix the issue.
Benjamin
30 May, 2010
./.autotest:17: warning: `&’ interpreted as argument prefix
./.autotest:17: warning: unused literal ignored
./.autotest:6: warning: redefine notify
are still warnings I get.
Line 17 is if $~[2].to_i > 0
and Line 6 def self.notify title, msg, img
Otherwise it seems to work, I get the pictures ;-) But how am I supposed to use autospec? Just start a terminal and run it and ignore the terminal afterwards? or how do I ideally run it continuously?
zarko acimovic
15 Jun, 2010
Hi Benjamin, you can follow http://www.railstutorial.org/ to see autotest in action :-)
zarko acimovic
17 Jun, 2010
you can also see screenshots from my environment here
http://uczareac.blogspot.com/2010/06/ruby-autotest-setup-notes-autospec.html
carl
23 Jun, 2010
im running ubuntu 10.04 i followed all the directions above and my autospec isnt giving me popups … any idea?
Swaroop
23 Jun, 2010
The post’s script didn’t work for me, found a super-simple way of installing notifications – http://github.com/nuxlli/autotest-notification
Tenorio
8 Jul, 2010
Great! Thanks!
mystdeim
11 Aug, 2010
$ autotest
loading autotest/rails
/home/deim/.rvm/gems/ruby-1.9.2-head/gems/test-unit-2.1.1/lib/test/unit/ui/console/testrunner.rb:295:in `’: uninitialized constant Test::Unit::UI::Console::Diff (NameError)
Whats wrong?
kenshin
1 Sep, 2010
@mystdeim
I have the same problem with you,
you can change the require ‘redgreen’ to gem ‘redgreen’
at your ~/.autotest