Skip to content

Instantly share code, notes, and snippets.

@benmacleod
Created January 19, 2012 06:29
Show Gist options
  • Save benmacleod/1638405 to your computer and use it in GitHub Desktop.
Save benmacleod/1638405 to your computer and use it in GitHub Desktop.
Autotest
#!/usr/bin/env ruby
#require 'redgreen/autotest'
AUTOTEST_IMAGE_PATH = File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : File.expand_path(__FILE__))
module Autotest::Notify
def self.notify title, msg, img, urgency='low'
system "notify-send -c autotest -i #{img.inspect} #{title.inspect} #{msg.inspect}"
end
Autotest.add_hook :ran_command do |autotest|
filtered = autotest.results.grep(/\d+\s.*examples?/)
output = filtered.empty? ? "" : filtered.last.slice(/(\d+)\s.*examples?,\s(\d+)\s.*failures?(?:,\s(\d+)\s.*pending)?/)
if output =~ /[1-9]\sfailures?/
notify "Test Results", "#{output}", "#{AUTOTEST_IMAGE_PATH}/fail.jpg"
elsif output =~ /pending/
notify "Test Results", "#{output}", "#{AUTOTEST_IMAGE_PATH}/pending.jpg"
else
notify "Test Results", "#{output}", "#{AUTOTEST_IMAGE_PATH}/ok.jpg"
end
end
end
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git .idea vendor}.each {|exception| at.add_exception(exception)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment