guard-test 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,40 @@
1
1
  # encoding: utf-8
2
2
  require 'guard'
3
3
  require 'guard/notifier'
4
- require 'guard/test/result_helpers'
5
4
 
6
5
  module Guard
7
6
  module TestNotifier
8
7
 
9
- def self.notify(result, elapsed_time)
10
- ::Guard::Notifier.notify(
11
- ::Guard::TestResultHelpers.summary(result) + "\n\n" + ::Guard::TestResultHelpers.duration(elapsed_time),
12
- :title => "Test::Unit results",
13
- :image => result.failure_count > 0 ? :failed : :success
14
- )
8
+ class << self
9
+ def notify(result, elapsed_time)
10
+ ::Guard::Notifier.notify(
11
+ summary(result) + "\n\n" + duration(elapsed_time),
12
+ :title => "Test::Unit results",
13
+ :image => result.failure_count > 0 ? :failed : :success
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def summary(result)
20
+ "#{result.run_count} test#{'s' if result.run_count != 1}, " \
21
+ "#{result.assertion_count} assert#{'s' if result.assertion_count != 1}, " \
22
+ "#{result.failure_count} fail#{'s' if result.failure_count != 1}, " \
23
+ "#{result.error_count} error#{'s' if result.error_count != 1}"
24
+ end
25
+
26
+ def duration(duration, options={})
27
+ "Finished in #{round_float(duration)} seconds"
28
+ end
29
+
30
+ def round_float(float, decimals=4)
31
+ if Float.instance_method(:round).arity == 0 # Ruby 1.8
32
+ factor = 10**decimals
33
+ (float*factor).round / factor.to_f
34
+ else # Ruby 1.9
35
+ float.round(decimals)
36
+ end
37
+ end
15
38
  end
16
39
 
17
40
  end