minitest-reporters 0.14.2 → 0.14.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
1
  source :rubygems
2
- gemspec
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ module MiniTest
2
+ module AroundTestHooks
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::Unit.runner.after_test(instance.class, instance.__name__)
9
+ end
10
+
11
+ def before_setup
12
+ AroundTestHooks.before_test(self)
13
+ super
14
+ end
15
+
16
+ def after_teardown
17
+ super
18
+ AroundTestHooks.after_test(self)
19
+ end
20
+ end
21
+ end
@@ -5,18 +5,25 @@ module MiniTest
5
5
  #
6
6
  # @see https://github.com/seattlerb/minitest MiniTest
7
7
  class ReporterRunner < Unit
8
- attr_accessor :suites_start_time, :test_start_time, :reporters, :test_results
8
+ extend Forwardable
9
9
 
10
- alias_method :suite_start_time, :start_time
10
+ attr_accessor :reporters
11
+ attr_reader :test_results
12
+ attr_reader :suites_start_time
13
+ attr_reader :suite_start_time
14
+ attr_reader :test_start_time
15
+
16
+ def_delegator :@test_recorder, :assertion_count
11
17
 
12
18
  def initialize
13
19
  super
14
20
  self.reporters = []
15
- self.test_results = {}
21
+ @test_results = {}
22
+ @test_recorder = TestRecorder.new
16
23
  end
17
24
 
18
25
  def _run_suites(suites, type)
19
- self.suites_start_time = Time.now
26
+ @suites_start_time = Time.now
20
27
  count_tests!(suites, type)
21
28
  trigger_callback(:before_suites, suites, type)
22
29
  super(suites, type)
@@ -25,63 +32,54 @@ module MiniTest
25
32
  end
26
33
 
27
34
  def _run_suite(suite, type)
35
+ @suite_start_time = Time.now
28
36
  trigger_callback(:before_suite, suite)
29
- self.start_time = Time.now
30
37
  super(suite, type)
31
38
  ensure
32
39
  trigger_callback(:after_suite, suite)
33
40
  end
34
41
 
35
42
  def before_test(suite, test)
36
- self.test_start_time = Time.now
43
+ @test_start_time = Time.now
37
44
  trigger_callback(:before_test, suite, test)
38
45
  end
39
46
 
40
47
  def record(suite, test, assertions, time, exception)
41
- self.assertion_count += assertions
42
-
43
- result = case exception
44
- when nil then :pass
45
- when Skip then :skip
46
- when Assertion then :failure
47
- else :error
48
- end
48
+ runner = TestRunner.new(suite,
49
+ test.to_sym,
50
+ assertions,
51
+ time,
52
+ exception)
49
53
 
50
- test_runner = TestRunner.new(
51
- suite,
52
- test.to_sym,
53
- assertions,
54
- time,
55
- result,
56
- exception
57
- )
58
-
59
- test_results[suite] ||= {}
60
- test_results[suite][test.to_sym] = test_runner
61
- trigger_callback(result, suite, test, test_runner)
54
+ @test_results[suite] ||= {}
55
+ @test_results[suite][test.to_sym] = runner
56
+ @test_recorder.record(runner)
62
57
  end
63
58
 
64
- def puts(*args)
65
- end
59
+ def after_test(suite, test)
60
+ runners = @test_recorder[suite, test.to_sym]
66
61
 
67
- def print(*args)
62
+ runners.each do |runner|
63
+ trigger_callback(runner.result, suite, test.to_sym, runner)
64
+ end
68
65
  end
69
66
 
70
- def status(io = output)
71
- end
67
+ # Stub out the three IO methods used by the built-in reporter.
68
+ def puts(*args); end
69
+ def print(*args); end
70
+ def status(io = output); end
72
71
 
73
72
  private
74
73
 
75
74
  def trigger_callback(callback, *args)
76
- reporters.each do |reporter|
77
- reporter.public_send(callback, *args)
78
- end
75
+ reporters.each { |r| r.public_send(callback, *args) }
79
76
  end
80
77
 
81
78
  def count_tests!(suites, type)
82
79
  filter = options[:filter] || '/./'
83
80
  filter = Regexp.new $1 if filter =~ /\/(.*)\//
84
- self.test_count = suites.inject(0) do |acc, suite|
81
+
82
+ @test_count = suites.inject(0) do |acc, suite|
85
83
  acc + suite.send("#{type}_methods").grep(filter).length
86
84
  end
87
85
  end
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  module Reporters
3
- VERSION = "0.14.2"
3
+ VERSION = "0.14.3"
4
4
  end
5
5
  end
@@ -4,8 +4,9 @@ module MiniTest
4
4
  require "minitest/relative_position"
5
5
  require "minitest/reporter"
6
6
  require "minitest/reporter_runner"
7
- require "minitest/before_test_hook"
7
+ require "minitest/around_test_hooks"
8
8
  require "minitest/test_runner"
9
+ require "minitest/test_recorder"
9
10
  require "minitest/extensible_backtrace_filter"
10
11
 
11
12
  module Reporters
@@ -34,10 +35,14 @@ module MiniTest
34
35
 
35
36
  def self.use_before_test_hook!
36
37
  if Unit::VERSION >= "3.3.0"
37
- Unit::TestCase.send(:include, BeforeTestHook)
38
+ Unit::TestCase.send(:include, AroundTestHooks)
38
39
  else
39
40
  Unit::TestCase.send(:define_method, :before_setup) do
40
- BeforeTestHook.before_test(self)
41
+ AroundTestHooks.before_test(self)
42
+ end
43
+
44
+ Unit::TestCase.send(:define_method, :after_teardown) do
45
+ AroundTestHooks.after_test(self)
41
46
  end
42
47
  end
43
48
  end
@@ -0,0 +1,22 @@
1
+ module MiniTest
2
+ class TestRecorder
3
+ def initialize
4
+ @records = {}
5
+ end
6
+
7
+ def [](suite, test)
8
+ name = [suite, test]
9
+ @records[name]
10
+ end
11
+
12
+ def record(runner)
13
+ name = [runner.suite, runner.test]
14
+ @records[name] ||= []
15
+ @records[name] << runner
16
+ end
17
+
18
+ def assertion_count
19
+ @records.inject(0) { |acc, r| acc + r.last.last.assertions }
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,12 @@
1
1
  module MiniTest
2
- TestRunner = Struct.new(:suite, :test, :assertions, :time, :result, :exception)
2
+ class TestRunner < Struct.new(:suite, :test, :assertions, :time, :exception)
3
+ def result
4
+ case exception
5
+ when nil then :pass
6
+ when Skip then :skip
7
+ when Assertion then :failure
8
+ else :error
9
+ end
10
+ end
11
+ end
3
12
  end
data/test/test_helper.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  if ENV["REPORTER"]
15
15
  reporter_klass = MiniTest::Reporters.const_get(ENV["REPORTER"])
16
- MiniTest::Reporters.use! [reporter_klass.new]
16
+ MiniTest::Reporters.use!(reporter_klass.new)
17
17
  else
18
18
  MiniTest::Reporters.use!(MiniTest::Reporters::DefaultReporter.new)
19
19
  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.2
4
+ version: 0.14.3
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-08 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -127,7 +127,7 @@ files:
127
127
  - LICENSE
128
128
  - README.md
129
129
  - Rakefile
130
- - lib/minitest/before_test_hook.rb
130
+ - lib/minitest/around_test_hooks.rb
131
131
  - lib/minitest/extensible_backtrace_filter.rb
132
132
  - lib/minitest/relative_position.rb
133
133
  - lib/minitest/reporter.rb
@@ -141,6 +141,7 @@ files:
141
141
  - lib/minitest/reporters/rubymine_reporter.rb
142
142
  - lib/minitest/reporters/spec_reporter.rb
143
143
  - lib/minitest/reporters/version.rb
144
+ - lib/minitest/test_recorder.rb
144
145
  - lib/minitest/test_runner.rb
145
146
  - minitest-reporters.gemspec
146
147
  - test/gallery/bad_test.rb
@@ -163,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
164
  version: '0'
164
165
  segments:
165
166
  - 0
166
- hash: -1266049475304988820
167
+ hash: 3603087580033239175
167
168
  required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  none: false
169
170
  requirements:
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
173
  version: '0'
173
174
  segments:
174
175
  - 0
175
- hash: -1266049475304988820
176
+ hash: 3603087580033239175
176
177
  requirements: []
177
178
  rubyforge_project: minitest-reporters
178
179
  rubygems_version: 1.8.24
@@ -1,16 +0,0 @@
1
- module MiniTest
2
- module BeforeTestHook
3
- def self.before_test(instance)
4
- runner = MiniTest::Unit.runner
5
-
6
- if runner.respond_to?(:before_test)
7
- runner.before_test(instance.class, instance.__name__)
8
- end
9
- end
10
-
11
- def before_setup
12
- BeforeTestHook.before_test(self)
13
- super
14
- end
15
- end
16
- end