Skip to content

Commit

Permalink
Require rubygems in order for require 'guard/notifier' to succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy Coutable committed Nov 5, 2011
1 parent 23358d7 commit 0b471bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
58 changes: 30 additions & 28 deletions lib/guard/test/notifier.rb
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
2 changes: 1 addition & 1 deletion spec/guard/test/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'spec_helper'
require 'guard/test/notifier'

describe Guard::TestNotifier do
describe Guard::Test::Notifier do

describe "#notify(result, duration)" do
context "no failure, no error" do
Expand Down

0 comments on commit 0b471bc

Please sign in to comment.