Skip to content

Instantly share code, notes, and snippets.

@nz
Created October 29, 2008 16:46
Show Gist options
  • Save nz/20742 to your computer and use it in GitHub Desktop.
Save nz/20742 to your computer and use it in GitHub Desktop.
My autotest config file. With colored Growl support for Test::Unit and RSpec. Save in ~/.autotest
require 'autotest/redgreen'
Autotest.send(:alias_method, :real_make_test_cmd, :make_test_cmd)
Autotest.send(:define_method, :make_test_cmd) do |*args|
real_make_test_cmd(*args).sub('test/unit', %[rubygems -e "require 'redgreen'"])
end
Autotest.add_hook :initialize do |autotest|
autotest.add_exception(/^\.\/vendor/)
autotest.add_exception(/\.svn/)
autotest.add_exception(/\.git/)
autotest.add_mapping(/stories\/all.rb/) do |f, _|
autotest.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
end
end
module Autotest::Growl
def self.growl title, msg, pri=-1, stick=""
system "growlnotify -n autotest -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
def self.parse_results(autotest_results)
keys = %w(test example failure error pending fixed)
output = (autotest_results.last||"")
results = {}
keys.each do |key|
output =~ /(\d+) #{key}/
results[key] = $1.to_i || 0
end
results
end
Autotest.add_hook :ran_command do |autotest|
autotest_output = (autotest.results.last||"").slice(/(\d+) (test||example)[^\e]*/)
output = parse_results(autotest.results)
if output['failure'] == 0 && output['error'] == 0 && output['pending'] == 0
growl "Test Results", autotest_output, -2
elsif output['failure'] == 0 && output['error'] == 0 && output['pending'] > 0
growl "Test Results", autotest_output, -1
elsif output['failure'] == 0 && output['error'] == 0
growl "Test Results", autotest_output, 0
elsif output['fixed'] > 0
growl "Test Results", autotest_output, 0
else
growl "Test Results", autotest_output, 1#, "-s"
end unless autotest_output.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment