Skip to content

Instantly share code, notes, and snippets.

@evtuhovich
Created September 11, 2009 09:20
Show Gist options
  • Save evtuhovich/185185 to your computer and use it in GitHub Desktop.
Save evtuhovich/185185 to your computer and use it in GitHub Desktop.
# .autotest file in project folder for Ubunty with Gnome Notification
module Autotest::GnomeNotify
EXPIRATION_IN_SECONDS = 5
FAIL_IMAGE = "gtk-dialog-error"
PENDING_IMAGE = "gtk-dialog-warning"
SUCCESS_IMAGE = "gtk-dialog-info"
def self.notify title, message, stock_icon
options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
system "notify-send #{options} '#{title}' '#{message}'"
end
Autotest.add_hook :ran_command do |at|
result = at.results.last
if result
tests = result =~ /(\d+) test/ ? $1.to_i : 0
assertions = result =~ /(\d+) assertion/ ? $1.to_i : 0
failures = result =~ /(\d+) failure/ ? $1.to_i : 0
errors = result =~ /(\d+) error/ ? $1.to_i : 0
examples = result =~ /(\d+) example/ ? $1.to_i : 0
pendings = result =~ /(\d+) pending/ ? $1.to_i : 0
if failures > 0 or errors > 0
notify "Tests Failed", "#{tests} tests\n#{assertions} assertions\n#{failures} failures\n#{errors} errors", FAIL_IMAGE
elsif pendings > 0
notify "Tests Pending", "#{tests} tests\n#{assertions} assertions\n#{failures} failures\n#{errors} errors\n#{pendings} pendings\n", PENDING_IMAGE
else
notify "Tests Passed", "#{tests} tests\n#{assertions} assertions\n#{failures} failures\n#{errors} errors", SUCCESS_IMAGE
end
end
end
end
Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^spec/(actions|management|matrix|policies|scheduler)/(.*)\.rb$%) { |filename, _|
filename
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment