-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require rubygems in order for require 'guard/notifier' to succeed
- Loading branch information
Rémy Coutable
committed
Nov 5, 2011
1 parent
23358d7
commit 0b471bc
Showing
2 changed files
with
31 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
# encoding: utf-8 | ||
require 'guard' | ||
require 'rubygems' | ||
require 'guard/notifier' | ||
|
||
module Guard | ||
module TestNotifier | ||
class Test | ||
module Notifier | ||
|
||
class << self | ||
def notify(result, elapsed_time) | ||
::Guard::Notifier.notify( | ||
summary(result) + "\n\n" + duration(elapsed_time), | ||
:title => "Test::Unit results", | ||
:image => result.failure_count > 0 ? :failed : :success | ||
) | ||
end | ||
class << self | ||
def notify(result, elapsed_time) | ||
::Guard::Notifier.notify( | ||
summary(result) + "\n\n" + duration(elapsed_time), | ||
:title => "Test::Unit results", | ||
:image => result.failure_count > 0 ? :failed : :success | ||
) | ||
end | ||
|
||
private | ||
private | ||
|
||
def summary(result) | ||
"#{result.run_count} test#{'s' if result.run_count != 1}, " \ | ||
"#{result.assertion_count} assert#{'s' if result.assertion_count != 1}, " \ | ||
"#{result.failure_count} fail#{'s' if result.failure_count != 1}, " \ | ||
"#{result.error_count} error#{'s' if result.error_count != 1}" | ||
end | ||
def summary(result) | ||
"#{result.run_count} test#{'s' if result.run_count != 1}, " + | ||
"#{result.assertion_count} assert#{'s' if result.assertion_count != 1}, " + | ||
"#{result.failure_count} fail#{'s' if result.failure_count != 1}, " + | ||
"#{result.error_count} error#{'s' if result.error_count != 1}" | ||
end | ||
|
||
def duration(duration, options={}) | ||
"Finished in #{round_float(duration)} seconds" | ||
end | ||
def duration(duration, options = {}) | ||
"Finished in #{round_float(duration)} seconds" | ||
end | ||
|
||
def round_float(float, decimals=4) | ||
if Float.instance_method(:round).arity == 0 # Ruby 1.8 | ||
factor = 10**decimals | ||
(float*factor).round / factor.to_f | ||
else # Ruby 1.9 | ||
float.round(decimals) | ||
def round_float(float, decimals = 4) | ||
if Float.instance_method(:round).arity == 0 # Ruby 1.8 | ||
factor = 10**decimals | ||
(float*factor).round / factor.to_f | ||
else # Ruby 1.9 | ||
float.round(decimals) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
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