minitest-reporters 0.14.5 → 0.14.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,25 @@
1
1
  module MiniTest
2
2
  module AroundTestHooks
3
- def self.included(base)
4
- base.instance_eval do
5
- alias_method :run_without_hooks, :run
6
- alias_method :run, :run_with_hooks
3
+ def self.before_test(instance)
4
+ MiniTest::Unit.runner.before_test(instance.class, instance.__name__)
5
+ end
6
+
7
+ def self.after_test(instance)
8
+ # MiniTest < 4.1.0 sends #record after all teardown hooks, so don't call
9
+ # #after_test here.
10
+ if MiniTest::Unit::VERSION > "4.1.0"
11
+ MiniTest::Unit.runner.after_test(instance.class, instance.__name__)
7
12
  end
8
13
  end
9
14
 
10
- def run_with_hooks(runner)
11
- runner.before_test(self.class, self.__name__)
12
- run_without_hooks(runner)
13
- ensure
14
- runner.after_test(self.class, self.__name__)
15
+ def before_setup
16
+ AroundTestHooks.before_test(self)
17
+ super
18
+ end
19
+
20
+ def after_teardown
21
+ super
22
+ AroundTestHooks.after_test(self)
15
23
  end
16
24
  end
17
25
  end
@@ -29,6 +29,7 @@ module MiniTest
29
29
  def before_suite(suite); end
30
30
  def after_suite(suite); end
31
31
  def before_test(suite, test); end
32
+ def after_test(suite, test); end
32
33
  def pass(suite, test, test_runner); end
33
34
  def skip(suite, test, test_runner); end
34
35
  def failure(suite, test, test_runner); end
@@ -56,6 +56,10 @@ module MiniTest
56
56
  @test_results[suite] ||= {}
57
57
  @test_results[suite][test.to_sym] = runner
58
58
  @test_recorder.record(runner)
59
+
60
+ # MiniTest < 4.1.0 sends #record after all teardown hooks, so explicitly
61
+ # call #after_test here after recording.
62
+ after_test(suite, test) if Unit::VERSION <= "4.1.0"
59
63
  end
60
64
 
61
65
  def after_test(suite, test)
@@ -64,6 +68,8 @@ module MiniTest
64
68
  runners.each do |runner|
65
69
  trigger_callback(runner.result, suite, test.to_sym, runner)
66
70
  end
71
+
72
+ trigger_callback(:after_test, suite, test.to_sym)
67
73
  end
68
74
 
69
75
  # Stub out the three IO methods used by the built-in reporter.
@@ -22,7 +22,7 @@ module MiniTest
22
22
 
23
23
  def self.use!(console_reporters = ProgressReporter.new, env = ENV, backtrace_filter = ExtensibleBacktraceFilter.default_filter)
24
24
  use_runner!(console_reporters, env)
25
- use_around_test_hooks!
25
+ use_before_test_hook!
26
26
  use_backtrace_filter!(backtrace_filter)
27
27
  use_parallel_length_method!
28
28
  end
@@ -33,8 +33,18 @@ module MiniTest
33
33
  Unit.runner = runner
34
34
  end
35
35
 
36
- def self.use_around_test_hooks!
37
- Unit::TestCase.send(:include, AroundTestHooks)
36
+ def self.use_before_test_hook!
37
+ if Unit::VERSION >= "3.3.0"
38
+ Unit::TestCase.send(:include, AroundTestHooks)
39
+ else
40
+ Unit::TestCase.send(:define_method, :before_setup) do
41
+ AroundTestHooks.before_test(self)
42
+ end
43
+
44
+ Unit::TestCase.send(:define_method, :after_teardown) do
45
+ AroundTestHooks.after_test(self)
46
+ end
47
+ end
38
48
  end
39
49
 
40
50
  def self.use_backtrace_filter!(backtrace_filter)
@@ -40,11 +40,11 @@ module MiniTest
40
40
  end
41
41
 
42
42
  def pass(suite, test, test_runner)
43
- after_test(green('.'))
43
+ test_result(green('.'))
44
44
  end
45
45
 
46
46
  def skip(suite, test, test_runner)
47
- after_test(yellow('S'))
47
+ test_result(yellow('S'))
48
48
  end
49
49
 
50
50
  def failure(suite, test, test_runner)
@@ -56,7 +56,7 @@ module MiniTest
56
56
  puts
57
57
  print_info(test_runner.exception)
58
58
  else
59
- after_test(red('F'))
59
+ test_result(red('F'))
60
60
  end
61
61
  end
62
62
 
@@ -69,7 +69,7 @@ module MiniTest
69
69
  puts
70
70
  print_info(test_runner.exception)
71
71
  else
72
- after_test(red('E'))
72
+ test_result(red('E'))
73
73
  end
74
74
  end
75
75
 
@@ -157,7 +157,7 @@ module MiniTest
157
157
  end
158
158
  end
159
159
 
160
- def after_test(result)
160
+ def test_result(result)
161
161
  time = Time.now - (runner.test_start_time || Time.now)
162
162
  @test_times << [@test_name, time]
163
163
 
@@ -43,7 +43,7 @@ module MiniTest
43
43
  }, true)
44
44
  end
45
45
 
46
- def pass(suite, test, test_runner)
46
+ def after_test(suite, test)
47
47
  increment
48
48
  end
49
49
 
@@ -57,7 +57,6 @@ module MiniTest
57
57
  end
58
58
 
59
59
  self.color = YELLOW unless color == RED
60
- increment
61
60
  end
62
61
 
63
62
  def failure(suite, test, test_runner)
@@ -69,7 +68,6 @@ module MiniTest
69
68
  puts
70
69
 
71
70
  self.color = RED
72
- increment
73
71
  end
74
72
 
75
73
  def error(suite, test, test_runner)
@@ -81,7 +79,6 @@ module MiniTest
81
79
  puts
82
80
 
83
81
  self.color = RED
84
- increment
85
82
  end
86
83
 
87
84
  def after_suites(suites, type)
@@ -95,24 +95,25 @@ else
95
95
  log(@message_factory.create_test_started(test, minitest_test_location(fqn)))
96
96
  end
97
97
 
98
- def pass(suite, test, test_runner)
99
- test_finished(test, test_runner)
98
+ def after_test(suite, test)
99
+ duration_ms = get_current_time_in_ms() - get_time_in_ms(runner.test_start_time || Time.now)
100
+ log(@message_factory.create_test_finished(test, duration_ms.nil? ? 0 : duration_ms))
100
101
  end
101
102
 
102
103
  def skip(suite, test, test_runner)
103
- test_finished(test, test_runner) do |exception_msg, backtrace|
104
+ with_result(test, test_runner) do |exception_msg, backtrace|
104
105
  log(@message_factory.create_test_ignored(test, exception_msg, backtrace))
105
106
  end
106
107
  end
107
108
 
108
109
  def failure(suite, test, test_runner)
109
- test_finished(test, test_runner) do |exception_msg, backtrace|
110
+ with_result(test, test_runner) do |exception_msg, backtrace|
110
111
  log(@message_factory.create_test_failed(test, exception_msg, backtrace))
111
112
  end
112
113
  end
113
114
 
114
115
  def error(suite, test, test_runner)
115
- test_finished(test, test_runner) do |exception_msg, backtrace|
116
+ with_result(test, test_runner) do |exception_msg, backtrace|
116
117
  log(@message_factory.create_test_error(test, exception_msg, backtrace))
117
118
  end
118
119
  end
@@ -132,23 +133,14 @@ else
132
133
  "ruby_minitest_qn://#{fqn}"
133
134
  end
134
135
 
135
- def test_finished(test, test_runner)
136
- duration_ms = get_current_time_in_ms() - get_time_in_ms(runner.test_start_time || Time.now)
137
-
138
- begin
139
- if block_given?
140
- exception = test_runner.exception
141
- msg = exception.nil? ? "" : "#{exception.class.name}: #{exception.message}"
142
- backtrace = exception.nil? ? "" : filter_backtrace(exception.backtrace).join("\n")
136
+ def with_result(test, test_runner)
137
+ exception = test_runner.exception
138
+ msg = exception.nil? ? "" : "#{exception.class.name}: #{exception.message}"
139
+ backtrace = exception.nil? ? "" : filter_backtrace(exception.backtrace).join("\n")
143
140
 
144
- yield(msg, backtrace)
145
- end
146
- ensure
147
- log(@message_factory.create_test_finished(test, duration_ms.nil? ? 0 : duration_ms))
148
- end
141
+ yield(msg, backtrace)
149
142
  end
150
143
  end
151
144
  end
152
145
  end
153
146
  end
154
-
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  module Reporters
3
- VERSION = "0.14.5"
3
+ VERSION = "0.14.6"
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ module MiniTestReportersTest
12
12
 
13
13
  def test_callbacks
14
14
  [
15
- :before_suites, :after_suite, :before_suite, :after_suite, :before_test,
15
+ :before_suites, :after_suite, :before_suite, :after_suite, :before_test, :after_test,
16
16
  :pass, :skip, :failure, :error
17
17
  ].each { |method| assert_respond_to @reporter, method }
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-reporters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.5
4
+ version: 0.14.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -2644503825152626631
167
+ hash: -1921564833427206097
168
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: -2644503825152626631
176
+ hash: -1921564833427206097
177
177
  requirements: []
178
178
  rubyforge_project: minitest-reporters
179
179
  rubygems_version: 1.8.24