Sha256: 51da04ee006e2c05bd0f649961f37964eb08bb1285eb226c7a197d30c7d2d539
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
$:.unshift(File.dirname(__FILE__)) require 'autotest_notification/linux' require 'autotest_notification/mac' require 'autotest_notification/windows' module AutotestNotification FAIL = -1 PENDING = 0 SUCCESS = 1 EXPIRATION_IN_SECONDS = 3 IMAGES_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../images/") SUCCESS_IMAGE = "#{IMAGES_DIRECTORY}/pass.png" FAIL_IMAGE = "#{IMAGES_DIRECTORY}/fail.png" Autotest.add_hook :ran_command do |at| result = at.results.is_a?(Array) ? at.results.last : at.results.split("\n").last if result # Test::Unit tests = result =~ /(\d+) test/ ? $1.to_i : 0 assertions = result =~ /(\d+) assertion/ ? $1.to_i : 0 errors = result =~ /(\d+) error/ ? $1.to_i : 0 # RSpec examples = result =~ /(\d+) example/ ? $1.to_i : 0 pendings = result =~ /(\d+) pending/ ? $1.to_i : 0 # Shared failures = result =~ /(\d+) failure/ ? $1.to_i : 0 code = 32 msg = if result =~ /test/ code = 31 if failures > 0 || errors > 0 "#{pluralize('test', tests)}, #{pluralize('assertion', assertions)}, #{pluralize('failure', failures)}, #{pluralize('error', errors)}" else code = (failures > 0) ? 31 : (pendings > 0) ? 33 : 32 "#{pluralize('example', examples)}, #{pluralize('failure', failures)}, #{pendings} pending" end if failures > 0 || errors > 0 notify "FAIL", msg, FAIL_IMAGE, 2 else notify "Pass", msg, SUCCESS_IMAGE end puts "\e[#{code}m#{'=' * 80}\e[0m\n\n" end end class << self def notify(title, msg, img = SUCCESS_IMAGE, pri = 0) case RUBY_PLATFORM when /linux/ Linux.notify(title, msg, img) when /darwin/ Mac.notify(title, msg, img, pri) when /mswin|cygwin/ Windows.notify(title, msg, img) end end def pluralize(text, number) "#{number} #{text}#{'s' if number != 1}" end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
carlosbrando-autotest-notification-0.1.0 | lib/autotest_notification.rb |
urubatan-autotest-notification-0.1.0 | lib/autotest_notification.rb |