Created
January 19, 2009 19:40
-
-
Save andyferra/49132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- ruby -*- | |
module Autotest::RedGreen | |
Autotest.send(:alias_method, :real_ruby, :ruby) | |
Autotest.send(:define_method, :ruby) do |*args| | |
real_ruby + %[ -rrubygems -e "require 'redgreen'" ] | |
end | |
# Clean the output so other modules can work correctly | |
Autotest.add_hook :ran_command do |at| | |
at.results.each do |r| | |
r.gsub!("\033[31m", "") | |
r.gsub!("\033[32m", "") | |
r.gsub!("\033[33m", "") | |
r.gsub!("\033[0m", "") | |
end | |
end | |
end | |
module Autotest::Growl | |
AUTOTEST_IMAGE_ROOT = "~/.autotest_icons" | |
def self.growl(title, msg, img, pri=0, sticky="") | |
system "growlnotify -n autotest --image #{img} -p #{pri} -m '#{msg}' #{title} #{sticky}" | |
end | |
Autotest.add_hook :red do |at| | |
growl("Test Results", get_results(at), "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2) | |
end | |
Autotest.add_hook :green do |at| | |
growl("Test Results", get_results(at), "#{AUTOTEST_IMAGE_ROOT}/pass.png") | |
end | |
private | |
def self.get_results(at) | |
results = [at.results].flatten.join("\n") | |
if results.include? 'tests' | |
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/) | |
else | |
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/) | |
end | |
output = output.gsub(/,\s/, "\n") | |
end | |
end | |
# Esclusioni | |
Autotest.add_hook :initialize do |at| | |
%w{.hg .git .svn stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts vendor/gems autotest svn-commit .DS_Store }.each do |exception| | |
at.add_exception(exception) | |
end | |
at.add_mapping(/spec\/defaults.rb/) do |f, _| | |
at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$% | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment