Created
August 26, 2008 18:46
-
-
Save chrisk/7317 to your computer and use it in GitHub Desktop.
My ~/.autotest
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
require 'pathname' | |
p = Pathname.new(__FILE__) | |
puts "loading #{p.realpath}" | |
# Load sound effects library and sounds | |
# From http://fozworks.com/2007/7/28/autotest-sound-effects | |
require '~/.autotest_extras/sound.rb' | |
Autotest::Sound.sound_path = "~/.autotest_extras/sound_fx/" | |
# Tell autotest to ignore changes to files that infrequently change or aren't related | |
# to our tests | |
# From http://www.nabble.com/Re%3A-changes-in-rspec%27s-trunk-and-autotest-p14759325.html | |
Autotest.add_hook :initialize do |at| | |
%w(.svn .git .DS_Store .rake .tar.gz .jpg .png stories tmtags Rakefile | |
Capfile README vendor/gems vendor/plugins vendor/rails .log db/migrate | |
db/schema doc/api doc/plugins script config public spec/spec.opts | |
spec/rcov.opts .autotest).each do |exception| | |
at.add_exception(exception) | |
end | |
end | |
# Configure Autotest to use Growl for test results notifications | |
# From http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl | |
module Autotest::Growl | |
def self.growl title, msg, img, pri=0, sticky="" | |
# growlnotify supposedly works now under Leopard; you can use AppleScript | |
# instead if you want | |
# system "osascript ~/.autotest_extras/growlNotify.applescript '#{title}' '#{msg}' '#{img}' '#{pri}'" | |
`growlnotify -n autotest --image "#{img}" -p "#{pri}" -m "#{msg}" "#{title}" #{sticky}` | |
end | |
Autotest.add_hook :ran_command do |at| | |
image_root = "/Users/chrisk/.autotest_extras/images" | |
results = [at.results].flatten.last | |
is_rspec = results =~ /example/ | |
is_testunit = results =~ /test/ | |
is_hook_misfire = results.nil? | |
if is_rspec | |
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) | |
num_errors = $~[2].to_i | |
num_pending = $~[4].nil? ? 0 : $~[4].to_i | |
elsif is_testunit | |
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?,\s*(\d+)\s+errors?/) | |
num_errors = $~[3].to_i + $~[4].to_i | |
num_pending = 0 | |
elsif is_hook_misfire | |
output = "Hook misfire: a file changed with no mapping to a test. Add an autotest exception?" | |
num_errors = 0 | |
num_pending = 1 | |
else | |
output = "Exception raised during tests" | |
num_errors = 1 | |
end | |
if output | |
if num_errors > 0 | |
growl "Fail", "#{output}", "#{image_root}/fail_whale.png", 2 | |
elsif num_pending > 0 | |
growl "Incomplete", "#{output}", "#{image_root}/rails_warning.png", 1 | |
else | |
growl "Pass", "#{output}", "#{image_root}/rails_pass.png", -2 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment