minitest-reporters 0.14.24 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58d931f0048a34745fe468c31728f2d665b9f269
4
- data.tar.gz: 1b8037b1afda1bc3535e88d3ffde9aecc2a98c2b
3
+ metadata.gz: 6a4b6d764247a5143cb75e59c7f421ffe3a0d6bb
4
+ data.tar.gz: 1202b2149bafac15280beaa41b16380032952ef1
5
5
  SHA512:
6
- metadata.gz: 9b06f69f55a81ac3cb53447bbebd5d984ab8474aa71b37b185cda55ac84c3a6a30cabe68b24af4f733881ca4705573429db75949e02efbb81ca8c6ac92cd7dd4
7
- data.tar.gz: c6bbd884a420a4d55808623b4080e084e53cb52b79819d5b5657b06a1c8dc10418062f953d990e2beae3df17c85e5e768483ddc00f2bf8b7ce58bf509792f79f
6
+ metadata.gz: 8b070ec5fba6d3dbf4167b4fda5cbb3c2196ae3e8e68a9c90de21b69974e2a2d2ce9653f03137983d46042b2afd5e222565a2e90f7147b4055e907637592712f
7
+ data.tar.gz: 376e26b5042f5c6ea2b4705fd4788f0cb72bc4cb5315d3ba07b5eb16985016cea9c00ee098c13367efdd18f4d9391b9b5b554011314596c558b0b4ec8cdf2d0f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # minitest-reporters - create customizable MiniTest output formats [![Build Status](https://secure.travis-ci.org/axskern/minitest-reporters.png)](http://travis-ci.org/axskern/minitest-reporters)
1
+ # minitest-reporters - create customizable Minitest output formats [![Build Status](https://secure.travis-ci.org/axskern/minitest-reporters.png)](http://travis-ci.org/axskern/minitest-reporters)
2
2
 
3
- Death to haphazard monkey-patching! Extend MiniTest through simple hooks.
3
+ Death to haphazard monkey-patching! Extend Minitest through simple hooks.
4
4
 
5
5
  ## Installation ##
6
6
 
@@ -12,45 +12,44 @@ In your `test_helper.rb` file, add the following lines:
12
12
 
13
13
  ```ruby
14
14
  require "minitest/reporters"
15
- MiniTest::Reporters.use!
15
+ Minitest::Reporters.use!
16
16
  ```
17
17
 
18
- This will swap out the MiniTest runner to the custom one used by minitest-reporters and use the correct reporters for Textmate, Rubymine, and the console. If you would like to write your own reporter, just `include MiniTest::Reporter` and override the methods you'd like. Take a look at the provided reporters for examples.
18
+ This will swap out the Minitest runner to the custom one used by minitest-reporters and use the correct reporters for Textmate, Rubymine, and the console. If you would like to write your own reporter, just `include Minitest::Reporter` and override the methods you'd like. Take a look at the provided reporters for examples.
19
19
 
20
20
  Don't like the default progress bar reporter?
21
21
 
22
22
  ```ruby
23
- MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
23
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
24
24
  ```
25
25
 
26
26
  Want to use multiple reporters?
27
27
 
28
28
  ```ruby
29
- MiniTest::Reporters.use! [MiniTest::Reporters::SpecReporter.new, MiniTest::Reporters::GuardReporter.new]
29
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new, Minitest::Reporters::JUnitReporter]
30
30
  ```
31
31
 
32
32
  The following reporters are provided:
33
33
 
34
34
  ```ruby
35
- MiniTest::Reporters::DefaultReporter # => Redgreen-capable version of standard MiniTest reporter
36
- MiniTest::Reporters::SpecReporter # => Turn-like output that reads like a spec
37
- MiniTest::Reporters::ProgressReporter # => Fuubar-like output with a progress bar
38
- MiniTest::Reporters::RubyMateReporter # => Simple reporter designed for RubyMate
39
- MiniTest::Reporters::RubyMineReporter # => Reporter designed for RubyMine IDE and TeamCity CI server
40
- MiniTest::Reporters::GuardReporter # => Integrates with guard-minitest to provide on-screen notifications
41
- MiniTest::Reporters::JUnitReporter # => JUnit test reporter designed for JetBrains TeamCity
35
+ Minitest::Reporters::DefaultReporter # => Redgreen-capable version of standard Minitest reporter
36
+ Minitest::Reporters::SpecReporter # => Turn-like output that reads like a spec
37
+ Minitest::Reporters::ProgressReporter # => Fuubar-like output with a progress bar
38
+ Minitest::Reporters::RubyMateReporter # => Simple reporter designed for RubyMate
39
+ Minitest::Reporters::RubyMineReporter # => Reporter designed for RubyMine IDE and TeamCity CI server
40
+ Minitest::Reporters::JUnitReporter # => JUnit test reporter designed for JetBrains TeamCity
42
41
  ```
43
42
 
44
43
  Options can be passed to these reporters at construction-time, e.g. to force
45
44
  color output from `DefaultReporter`:
46
45
 
47
46
  ```ruby
48
- MiniTest::Reporters.use! [MiniTest::Reporters::SpecReporter.new(:color => true)]
47
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new(:color => true)]
49
48
  ```
50
49
 
51
50
  ## Caveats ##
52
51
 
53
- If you are using minitest-reporters with ActiveSupport 3.x, make sure that you require ActiveSupport before invoking `MiniTest::Reporters.use!`. Minitest-reporters fixes incompatibilities caused by monkey patches in ActiveSupport 3.x. ActiveSupport 4.x is unaffected.
52
+ If you are using minitest-reporters with ActiveSupport 3.x, make sure that you require ActiveSupport before invoking `Minitest::Reporters.use!`. Minitest-reporters fixes incompatibilities caused by monkey patches in ActiveSupport 3.x. ActiveSupport 4.x is unaffected.
54
53
 
55
54
  ## Note on Patches/Pull Requests ##
56
55
 
data/Rakefile CHANGED
@@ -21,9 +21,6 @@ end
21
21
 
22
22
  # - RubyMineReporter must be tested separately inside of RubyMine
23
23
  # - JUnitReporter normally writes to `test/reports` instead of stdout
24
- # - GuardReporter requires Guard, and I'm not
25
- # really all that interested in setting it up for automated testing for such a
26
- # simple reporter.
27
24
  task :gallery do
28
25
  unless rubymine_home
29
26
  warn "To see RubyMineReporter supply RUBYMINE_HOME= or git clone git://git.jetbrains.org/idea/contrib.git ../rubymine-contrib"
@@ -36,8 +33,7 @@ task :gallery do
36
33
  "ProgressReporter",
37
34
  "RubyMateReporter",
38
35
  "SpecReporter",
39
- "RubyMineReporter",
40
- "GuardReporter"
36
+ "RubyMineReporter"
41
37
  ].each do |reporter|
42
38
  puts
43
39
  puts "-" * 72
@@ -1,12 +1,12 @@
1
- module MiniTest
1
+ module Minitest
2
2
  # Filters backtraces of exceptions that may arise when running tests.
3
3
  class ExtensibleBacktraceFilter
4
4
  # Returns the default filter.
5
5
  #
6
- # The default filter will filter out all MiniTest and minitest-reporters
6
+ # The default filter will filter out all Minitest and minitest-reporters
7
7
  # lines.
8
8
  #
9
- # @return [MiniTest::ExtensibleBacktraceFilter]
9
+ # @return [Minitest::ExtensibleBacktraceFilter]
10
10
  def self.default_filter
11
11
  unless defined? @default_filter
12
12
  filter = self.new
@@ -48,7 +48,7 @@ module MiniTest
48
48
  #
49
49
  # @param [Array] backtrace the backtrace to filter
50
50
  # @return [Array] the filtered backtrace
51
- # @note This logic is based off of MiniTest's #filter_backtrace.
51
+ # @note This logic is based off of Minitest's #filter_backtrace.
52
52
  def filter(backtrace)
53
53
  result = []
54
54
  return result unless backtrace
@@ -0,0 +1,29 @@
1
+ module Minitest
2
+ class << self
3
+ def plugin_minitest_reporter_init(options)
4
+ if defined?(Minitest::Reporters) && Minitest::Reporters.reporters
5
+ reporter.reporters = Minitest::Reporters.reporters + guard_reporter
6
+ reporter.reporters.each do |reporter|
7
+ reporter.io = options[:io]
8
+ reporter.add_defaults(options.merge(:total_count => total_count(options)))
9
+ end
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ # stolen from minitest self.run
16
+ def total_count(options)
17
+ filter = options[:filter] || '/./'
18
+ filter = Regexp.new $1 if filter =~ /\/(.*)\//
19
+
20
+ Minitest::Runnable.runnables.map(&:runnable_methods).flatten.find_all { |m|
21
+ filter === m || filter === "#{self}##{m}"
22
+ }.size
23
+ end
24
+
25
+ def guard_reporter
26
+ Array(reporter.reporters.detect { |r| r.class.name == "Guard::Minitest::Reporter" })
27
+ end
28
+ end
29
+ end
@@ -3,7 +3,7 @@ require "active_support/testing/setup_and_teardown"
3
3
  module ActiveSupport
4
4
  module Testing
5
5
  module SetupAndTeardown
6
- module ForMiniTest
6
+ module ForMinitest
7
7
  remove_method :run
8
8
 
9
9
  def before_setup
@@ -1,4 +1,4 @@
1
- module MiniTest
1
+ module Minitest
2
2
  module RelativePosition
3
3
  TEST_PADDING = 2
4
4
  TEST_SIZE = 63
@@ -11,7 +11,7 @@ module MiniTest
11
11
  puts pad(line, INFO_PADDING)
12
12
  end
13
13
 
14
- def pad(str, size)
14
+ def pad(str, size = INFO_PADDING)
15
15
  ' ' * size + str
16
16
  end
17
17
 
@@ -0,0 +1,88 @@
1
+ module Minitest
2
+ module Reporters
3
+ class BaseReporter < Minitest::StatisticsReporter
4
+ attr_accessor :total_count
5
+ attr_accessor :tests
6
+
7
+ def initialize(options={})
8
+ super($stdout, options)
9
+ self.tests = []
10
+ end
11
+
12
+ def add_defaults(defaults)
13
+ self.options = defaults.merge(options)
14
+ end
15
+
16
+ # called by our own before hooks
17
+ def before_test(test)
18
+ last_test = tests.last
19
+ if last_test.class != test.class
20
+ after_suite(test.class) if last_test
21
+ before_suite(test.class)
22
+ end
23
+ end
24
+
25
+ def record(test)
26
+ super
27
+ tests << test
28
+ end
29
+
30
+ # called by our own after hooks
31
+ def after_test(test)
32
+ end
33
+
34
+ def report
35
+ super
36
+ after_suite(tests.last.class)
37
+ end
38
+
39
+ protected
40
+
41
+ def after_suite(test)
42
+ end
43
+
44
+ def before_suite(test)
45
+ end
46
+
47
+ def result(test)
48
+ if test.error?
49
+ :error
50
+ elsif test.failure
51
+ :fail
52
+ elsif test.skipped?
53
+ :skip
54
+ else
55
+ :pass
56
+ end
57
+ end
58
+
59
+ def total_time
60
+ super || Time.now - start_time
61
+ end
62
+
63
+ def total_count
64
+ options[:total_count]
65
+ end
66
+
67
+ def filter_backtrace(backtrace)
68
+ Minitest.filter_backtrace(backtrace)
69
+ end
70
+
71
+ def puts(*args)
72
+ io.puts(*args)
73
+ end
74
+
75
+ def print(*args)
76
+ io.print(*args)
77
+ end
78
+
79
+ def print_info(e, name=true)
80
+ print "#{e.exception.class.to_s}: " if name
81
+ e.message.each_line { |line| print_with_info_padding(line) }
82
+
83
+ trace = filter_backtrace(e.backtrace)
84
+ trace.each { |line| print_with_info_padding(line) }
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,111 +1,81 @@
1
1
  require 'ansi/code'
2
2
 
3
- module MiniTest
3
+ module Minitest
4
4
  module Reporters
5
- # A reporter identical to the standard MiniTest reporter except with more
5
+ # A reporter identical to the standard Minitest reporter except with more
6
6
  # colors.
7
7
  #
8
- # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License).
8
+ # Based upon Ryan Davis of Seattle.rb's Minitest (MIT License).
9
9
  #
10
- # @see https://github.com/seattlerb/minitest MiniTest
11
- class DefaultReporter
12
- include Reporter
10
+ # @see https://github.com/seattlerb/minitest Minitest
11
+ class DefaultReporter < BaseReporter
13
12
  include RelativePosition
14
13
 
15
14
  def initialize(options = {})
15
+ super
16
16
  @detailed_skip = options.fetch(:detailed_skip, true)
17
17
  @slow_count = options.fetch(:slow_count, 0)
18
18
  @slow_suite_count = options.fetch(:slow_suite_count, 0)
19
19
  @fast_fail = options.fetch(:fast_fail, false)
20
- @test_times = []
21
- @suite_times = []
22
- @color = options.fetch(:color) do
23
- output.tty? && (
24
- ENV["TERM"] =~ /^screen|color/ ||
25
- ENV["EMACS"] == "t"
26
- )
27
- end
20
+ @options = options
28
21
  end
29
22
 
30
- def before_suites(suites, type)
23
+ def start
24
+ super
31
25
  puts
32
- puts "# Running #{type}s:"
26
+ puts "# Running tests:"
33
27
  puts
34
28
  end
35
29
 
36
- def before_test(suite, test)
37
- @test_name = "#{suite}##{test}"
38
- print "#{@test_name} = " if verbose?
30
+ def before_test(test)
31
+ super
32
+ print "\n#{test.class}##{test.name} " if options[:verbose]
39
33
  end
40
34
 
41
- def pass(suite, test, test_runner)
42
- test_result(green('.'))
43
- end
35
+ def record(test)
36
+ super
44
37
 
45
- def skip(suite, test, test_runner)
46
- test_result(yellow('S'))
47
- end
38
+ print "#{"%.2f" % test.time} = " if options[:verbose]
48
39
 
49
- def failure(suite, test, test_runner)
50
- if @fast_fail
51
- puts
52
- puts suite.name
53
- print pad_test(test)
54
- print(red(pad_mark('FAIL')))
55
- puts
56
- print_info(test_runner.exception, false)
57
- else
58
- test_result(red('F'))
59
- end
60
- end
40
+ print(if test.passed?
41
+ green('.')
42
+ elsif test.skipped?
43
+ yellow('S')
44
+ elsif test.failure
45
+ red('F')
46
+ end)
61
47
 
62
- def error(suite, test, test_runner)
63
- if @fast_fail
64
- puts
65
- puts suite.name
66
- print pad_test(test)
67
- print(red(pad_mark('ERROR')))
48
+ if @fast_fail && (test.skipped? || test.failure)
68
49
  puts
69
- print_info(test_runner.exception)
70
- else
71
- test_result(red('E'))
50
+ print_failure(test)
72
51
  end
73
52
  end
74
53
 
75
- def after_suite(suite)
76
- time = Time.now - runner.suite_start_time
77
- @suite_times << [suite.name, time]
78
- end
79
-
80
- def after_suites(suites, type)
81
- time = Time.now - runner.suites_start_time
82
- status_line = "Finished %ss in %.6fs, %.4f tests/s, %.4f assertions/s." %
83
- [type, time, runner.test_count / time, runner.assertion_count / time]
54
+ def report
55
+ super
56
+ status_line = "Finished tests in %.6fs, %.4f tests/s, %.4f assertions/s." %
57
+ [total_time, count / total_time, assertions / total_time]
84
58
 
85
59
  puts
86
60
  puts
87
61
  puts colored_for(suite_result, status_line)
88
62
 
89
63
  unless @fast_fail
90
- runner.test_results.each do |suite, tests|
91
- tests.each do |test, test_runner|
92
- if message = message_for(test_runner)
93
- puts
94
- print colored_for(test_runner.result, message)
95
- end
96
- end
64
+ tests.reject(&:passed?).each do |test|
65
+ puts
66
+ print_failure(test)
97
67
  end
98
68
  end
99
69
 
100
70
  if @slow_count > 0
101
- slow_tests = @test_times.sort_by { |x| x[1] }.reverse.take(@slow_count)
71
+ slow_tests = tests.sort_by(&:time).reverse.take(@slow_count)
102
72
 
103
73
  puts
104
74
  puts "Slowest tests:"
105
75
  puts
106
76
 
107
- slow_tests.each do |slow_test|
108
- puts "%.6fs %s" % [slow_test[1], slow_test[0]]
77
+ slow_tests.each do |test|
78
+ puts "%.6fs %s" % [test.time, "#{test.name}##{test.class}"]
109
79
  end
110
80
  end
111
81
 
@@ -126,23 +96,37 @@ module MiniTest
126
96
  puts
127
97
  end
128
98
 
99
+ def print_failure(test)
100
+ puts colored_for(result(test), message_for(test))
101
+ end
102
+
129
103
  private
130
104
 
105
+ def color?
106
+ return @color if defined?(@color)
107
+ @color = @options.fetch(:color) do
108
+ io.tty? && (
109
+ ENV["TERM"] =~ /^screen|color/ ||
110
+ ENV["EMACS"] == "t"
111
+ )
112
+ end
113
+ end
114
+
131
115
  def green(string)
132
- @color ? ANSI::Code.green(string) : string
116
+ color? ? ANSI::Code.green(string) : string
133
117
  end
134
118
 
135
119
  def yellow(string)
136
- @color ? ANSI::Code.yellow(string) : string
120
+ color? ? ANSI::Code.yellow(string) : string
137
121
  end
138
122
 
139
123
  def red(string)
140
- @color ? ANSI::Code.red(string) : string
124
+ color? ? ANSI::Code.red(string) : string
141
125
  end
142
126
 
143
127
  def colored_for(result, string)
144
128
  case result
145
- when :failure, :error; red(string)
129
+ when :fail, :error; red(string)
146
130
  when :skip; yellow(string)
147
131
  else green(string)
148
132
  end
@@ -150,22 +134,13 @@ module MiniTest
150
134
 
151
135
  def suite_result
152
136
  case
153
- when runner.failures > 0; :failure
154
- when runner.errors > 0; :error
155
- when runner.skips > 0; :skip
137
+ when failures > 0; :fail
138
+ when errors > 0; :error
139
+ when skips > 0; :skip
156
140
  else :pass
157
141
  end
158
142
  end
159
143
 
160
- def test_result(result)
161
- time = Time.now - (runner.test_start_time || Time.now)
162
- @test_times << [@test_name, time]
163
-
164
- print '%.2f s = ' % time if verbose?
165
- print result
166
- puts if verbose?
167
- end
168
-
169
144
  def location(exception)
170
145
  last_before_assertion = ''
171
146
 
@@ -177,33 +152,24 @@ module MiniTest
177
152
  last_before_assertion.sub(/:in .*$/, '')
178
153
  end
179
154
 
180
- def message_for(test_runner)
181
- suite = test_runner.suite
182
- test = test_runner.test
183
- e = test_runner.exception
155
+ def message_for(test)
156
+ e = test.failure
184
157
 
185
- case test_runner.result
186
- when :pass then nil
187
- when :skip
158
+ if test.skipped?
188
159
  if @detailed_skip
189
- "Skipped:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
160
+ "Skipped:\n#{test.class}##{test.name} [#{location(e)}]:\n#{e.message}"
190
161
  end
191
- when :failure then "Failure:\n#{test}(#{suite}) [#{location(e)}]:\n#{e.message}\n"
192
- when :error
193
- bt = filter_backtrace(test_runner.exception.backtrace).join "\n "
194
- "Error:\n#{test}(#{suite}):\n#{e.class}: #{e.message}\n #{bt}\n"
162
+ elsif test.error?
163
+ bt = filter_backtrace(e.backtrace).join "\n "
164
+ "Error:\n#{test.class}##{test.name}:\n#{e.class}: #{e.message}\n #{bt}"
165
+ else
166
+ "Failure:\n#{test.class}##{test.name}:\n#{e.class}: #{e.message}"
195
167
  end
196
168
  end
197
169
 
198
170
  def result_line
199
171
  '%d tests, %d assertions, %d failures, %d errors, %d skips' %
200
- [runner.test_count, runner.assertion_count, runner.failures, runner.errors, runner.skips]
201
- end
202
-
203
- def print_info(e, name = true)
204
- print "#{e.exception.class.to_s}: " if name
205
- e.message.each_line { |line| print_with_info_padding(line) }
206
- filter_backtrace(e.backtrace).each { |line| print_with_info_padding(line) }
172
+ [count, assertions, failures, errors, skips]
207
173
  end
208
174
  end
209
175
  end