I haven’t run Autotest in a while (i’ve been knee deep in JavaScript code lately). While I was away they’ve release a new version of the system. Last time I used it - I was only doing RSpec testing. Now that I’m working on a project that has Test Unit (Haven’t migrated the app yet) - autotest doesn’t work.
Below is a new .autotest file which handles figuring out which kind of testing you are doing and handle it accordingly.
require 'pp'
require 'autotest/timestamp'
require "#{ENV['HOME']}/autotest/sound/sound.rb”
Autotest::Sound.sound_path = “#{ENV['HOME']}/autotest/sound/sound_fx/”
require ‘rnotify’
require ‘gtk2′
module Autotest::RNotify
class Notification
attr_accessor :verbose, :image_root, :tray_icon, :notification,
:image_pass, :image_pending, :image_fail
def initialize(timeout = 5000,
image_root = “#{ENV['HOME']}/autotest/images” ,
verbose = false)
self.verbose = verbose
self.image_root = image_root
puts ‘Autotest Hook: loading Notify’ if verbose
Notify.init(’Autotest’) || raise(’Failed to initialize Notify’)
puts ‘Autotest Hook: initializing tray icon’ if verbose
self.tray_icon = Gtk::StatusIcon.new
tray_icon.icon_name = ‘face-monkey’
tray_icon.tooltip = ‘RSpec Autotest’
puts ‘Autotest Hook: Creating Notifier’ if verbose
self.notification = Notify::Notification.new(’X', nil, nil, tray_icon)
notification.timeout = timeout
Thread.new { Gtk.main }
sleep 1
tray_icon.embedded? || raise(’Failed to set up tray icon’)
end
def notify(icon, tray, title, message)
notification.update(title, message, nil)
notification.pixbuf_icon = icon
tray_icon.tooltip = “Last Result: #{message}”
#tray_icon.icon_name = tray
tray_icon.pixbuf = icon
notification.show
end
def passed(title, message)
self.image_pass ||= Gdk::Pixbuf.new(”#{image_root}/pass.png”, 48,48)
notify(image_pass, ‘face-smile’, title, message)
end
def pending(title, message)
self.image_pending ||= Gdk::Pixbuf.new(”#{image_root}/pending.png”,48,48)
notify(image_pending, ‘face-plain’, title, message)
end
def failed(title, message)
self.image_fail ||= Gdk::Pixbuf.new(”#{image_root}/fail.png”, 48,48)
notify(image_fail, ‘face-sad’, title, message)
end
def quit
puts ‘Autotest Hook: Shutting Down…’ if verbose
#Notify.uninit
Gtk.main_quit
end
end
Autotest.add_hook :initialize do |at|
@notify = Notification.new
%w{.hg .git .svn stories
tmtags Rakefile
Capfile README spec/spec.opts
spec/rcov.opts vendor vendor/gems autotest
svn-commit .DS_Store }.each {|exception|at.add_exception(exception)}
at.add_exception(/^\.\/vendor/)
end
Autotest.add_hook :ran_command do |at|
results = at.results.flatten.join(”\n”)
tests = 0
assertions = 0
failures = 0
errors = 0
pending = 0
unless results.nil?
rspec_tests = results.match(/(\d+)\sexample[s]?,/)
if rspec_tests
#Test unit
if (results.match(/(\d+)\sexample[s]?,\s(\d+)\sfailure[s]?,\s(\d+)\spending/))
test_results = results.match(/(\d+)\sexample[s]?,\s(\d+)\sfailure[s]?,\s(\d+)\spending/)[0]
results.scan(/(\d+)sexample[s]?,\s (\d+)failures[s]?,\s(\d+)\spending/) do |t, f, p |
tests += t.to_i
failures += f.to_i
pending += pending.to_i
end
else
test_results = results.match(/(\d+)\sexample[s]?,\s(\d+)\sfailure[s]?/)[0]
results.scan(/(\d+)sexample[s]?,\s (\d+)failures[s]?/) do |t, f |
tests += t.to_i
failures += f.to_i
end
end
else
#Test unit
test_results = results.match(/^\d+ tests, \d+ assertions, \d+ failures, \d+ errors/)[0]
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
end
if failures > 0
@notify.failed(”Tests Failed”, test_results)
elsif errors > 0
@notify.failed(”Tests Errors”, test_results)
elsif pending > 0
@notify.pending(”Tests Pending”, test_results)
else
unless at.tainted
@notify.passed(”All Tests Passed”, test_results)
else
@notify.passed(”Tests Passed”, test_results)
end
end
end
end
Autotest.add_hook :quit do |at|
puts “Goodbye”
@notify.quit
end
end