minitest-reporters 1.1.6 → 1.1.7

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: b6db7f6637aba345b2c1243184ea555e733820bd
4
- data.tar.gz: b2e10ea9d1a39f4bc08ff1c9c1a3b51e8a83bdd7
3
+ metadata.gz: 47b21650aa917c323c0dda549bbf596f3146f390
4
+ data.tar.gz: 178821e133b2c7472df9a37c800f681078f3c636
5
5
  SHA512:
6
- metadata.gz: 74d908229793593e956ffc86ade1ff4fab5f3763bd8cd942917e7f5bf0b3c83fe8780f41761e9410e582f76ca4abf4bdf24ccdd3dc4b0041fb9dc8b8579c6fb9
7
- data.tar.gz: 552b49c0f730980fdc976c8a814a5b18d662723fa7c2d6841d8875d676611f825053a8bc04a62ecaf55110f252808416f7ebd7c57d9e7e4e142d25150e9996a3
6
+ metadata.gz: d9014a80d115ad6531f6933c891ae9fc910442ca3a759e7432ff145f72829240ca1fca5f9aac9ebd0b57b52e6a629131ab900f9991faed835f15653e57c82360
7
+ data.tar.gz: fa0b84409d297219122aea2b5f55496127e250ac28400faffd4a38439fd44cbbc9d8a319f4905cd3ae744e6384b6a70eae3b45292ade68651b9df67ffe639dab
data/README.md CHANGED
@@ -45,6 +45,7 @@ Minitest::Reporters::ProgressReporter # => Fuubar-like output with a progress ba
45
45
  Minitest::Reporters::RubyMateReporter # => Simple reporter designed for RubyMate
46
46
  Minitest::Reporters::RubyMineReporter # => Reporter designed for RubyMine IDE and TeamCity CI server
47
47
  Minitest::Reporters::JUnitReporter # => JUnit test reporter designed for JetBrains TeamCity
48
+ Minitest::Reporters::MeanTimeReporter # => Produces a report summary showing the slowest running tests
48
49
  ```
49
50
 
50
51
  Options can be passed to these reporters at construction-time, e.g. to force
@@ -4,6 +4,7 @@ module Minitest
4
4
  module Code
5
5
 
6
6
  def self.color?
7
+ return false if ENV['MINITEST_REPORTERS_MONO']
7
8
  color_terminal = ENV['TERM'].to_s.downcase.include?("color")
8
9
  $stdout.tty? || color_terminal
9
10
  end
@@ -23,6 +23,9 @@ module Minitest
23
23
  #
24
24
  class MeanTimeReporter < Minitest::Reporters::DefaultReporter
25
25
 
26
+ class InvalidOrder < StandardError; end
27
+ class InvalidSortColumn < StandardError; end
28
+
26
29
  # Reset the statistics file for this reporter. Called via a rake task:
27
30
  #
28
31
  # rake reset_statistics
@@ -37,6 +40,13 @@ module Minitest
37
40
  # by description. Defaults to '/tmp/minitest_reporters_previous_run'.
38
41
  # @option report_filename [String] Contains the parsed results for the
39
42
  # last test run. Defaults to '/tmp/minitest_reporters_report'.
43
+ # @option show_count [Fixnum] The number of tests to show in the report
44
+ # summary at the end of the test run. Default is 15.
45
+ # @option sort_column [Symbol] One of :avg (default), :min, :max, :last.
46
+ # Determines the column by which the report summary is sorted.
47
+ # @option order [Symbol] One of :desc (default), or :asc. By default the
48
+ # report summary is listed slowest to fastest (:desc). :asc will order
49
+ # the report summary as fastest to slowest.
40
50
  # @return [Minitest::Reporters::MeanTimeReporter]
41
51
  def initialize(options = {})
42
52
  super
@@ -94,7 +104,9 @@ module Minitest
94
104
  # run.
95
105
  def defaults
96
106
  {
107
+ order: :desc,
97
108
  show_count: 15,
109
+ sort_column: :avg,
98
110
  previous_runs_filename: '/tmp/minitest_reporters_previous_run',
99
111
  report_filename: '/tmp/minitest_reporters_report',
100
112
  }
@@ -104,7 +116,9 @@ module Minitest
104
116
  #
105
117
  # @return [String]
106
118
  def report_title
107
- "\n\e[4mMinitest Reporters: Mean Time Report\e[24m (Samples: #{samples})\n"
119
+ "\n\e[4mMinitest Reporters: Mean Time Report\e[24m " \
120
+ "(Samples: #{samples}, Order: #{sort_column.inspect} " \
121
+ "#{order.inspect})\n"
108
122
  end
109
123
 
110
124
  # The report itself. Displays statistics about all runs, ideal for use
@@ -113,22 +127,43 @@ module Minitest
113
127
  #
114
128
  # @return [String]
115
129
  def report_body
130
+ order_sorted_body.each_with_object([]) do |result, obj|
131
+ rating = rate(result[:last], result[:min], result[:max])
132
+
133
+ obj << "#{avg_label} #{result[:avg]} " \
134
+ "#{min_label} #{result[:min]} " \
135
+ "#{max_label} #{result[:max]} " \
136
+ "#{run_label(rating)} #{result[:last]} " \
137
+ "#{des_label} #{result[:desc]}\n"
138
+ end.join
139
+ end
140
+
141
+ # @return [String] All of the column-sorted results sorted by the :order
142
+ # option. (Defaults to :desc).
143
+ def order_sorted_body
144
+ if desc?
145
+ column_sorted_body.reverse
146
+
147
+ elsif asc?
148
+ column_sorted_body
149
+
150
+ end
151
+ end
152
+
153
+ # @return [Array<Hash<Symbol => String>>] All of the results sorted by
154
+ # the :sort_column option. (Defaults to :avg).
155
+ def column_sorted_body
116
156
  previous_run.each_with_object([]) do |(description, timings), obj|
117
157
  size = Array(timings).size
118
158
  sum = Array(timings).inject { |total, x| total + x }
119
- avg = (sum / size).round(9).to_s.ljust(12)
120
- min = Array(timings).min.round(9).to_s.ljust(12)
121
- max = Array(timings).max.round(9).to_s.ljust(12)
122
- run = Array(timings).last.round(9).to_s.ljust(12)
123
-
124
- rating = rate(run, min, max)
125
-
126
- obj << "#{avg_label} #{avg} " \
127
- "#{min_label} #{min} " \
128
- "#{max_label} #{max} " \
129
- "#{run_label(rating)} #{run} " \
130
- "#{des_label} #{description}\n"
131
- end.sort.reverse.join
159
+ obj << {
160
+ avg: (sum / size).round(9).to_s.ljust(12),
161
+ min: Array(timings).min.round(9).to_s.ljust(12),
162
+ max: Array(timings).max.round(9).to_s.ljust(12),
163
+ last: Array(timings).last.round(9).to_s.ljust(12),
164
+ desc: description,
165
+ }
166
+ end.sort_by { |k| k[sort_column] }
132
167
  end
133
168
 
134
169
  # @return [Hash]
@@ -215,9 +250,11 @@ module Minitest
215
250
  end
216
251
 
217
252
  # Creates a new report file in the 'report_filename'. This file contains
218
- # a line for each test of the following example format:
253
+ # a line for each test of the following example format: (this is a single
254
+ # line despite explicit wrapping)
219
255
  #
220
- # Avg: 0.0555555 Min: 0.0498765 Max: 0.0612345 Last: 0.0499421 Description: The test name
256
+ # Avg: 0.0555555 Min: 0.0498765 Max: 0.0612345 Last: 0.0499421
257
+ # Description: The test name
221
258
  #
222
259
  # Note however the timings are to 9 decimal places, and padded to 12
223
260
  # characters and each label is coloured, Avg (yellow), Min (green),
@@ -288,6 +325,48 @@ module Minitest
288
325
  end
289
326
  end
290
327
 
328
+ # @return [Boolean] Whether the given :order option is :asc.
329
+ def asc?
330
+ order == :asc
331
+ end
332
+
333
+ # @return [Boolean] Whether the given :order option is :desc (default).
334
+ def desc?
335
+ order == :desc
336
+ end
337
+
338
+ # @raise [Minitest::Reporters::MeanTimeReporter::InvalidOrder]
339
+ # When the given :order option is invalid.
340
+ # @return [Symbol] The :order option, or by default; :desc.
341
+ def order
342
+ orders = [:desc, :asc]
343
+
344
+ if orders.include?(options[:order])
345
+ options[:order]
346
+
347
+ else
348
+ fail Minitest::Reporters::MeanTimeReporter::InvalidOrder,
349
+ "`:order` option must be one of #{orders.inspect}."
350
+
351
+ end
352
+ end
353
+
354
+ # @raise [Minitest::Reporters::MeanTimeReporter::InvalidSortColumn]
355
+ # When the given :sort_column option is invalid.
356
+ # @return [Symbol] The :sort_column option, or by default; :avg.
357
+ def sort_column
358
+ sort_columns = [:avg, :min, :max, :last]
359
+
360
+ if sort_columns.include?(options[:sort_column])
361
+ options[:sort_column]
362
+
363
+ else
364
+ fail Minitest::Reporters::MeanTimeReporter::InvalidSortColumn,
365
+ "`:sort_column` option must be one of #{sort_columns.inspect}."
366
+
367
+ end
368
+ end
369
+
291
370
  end
292
371
  end
293
372
  end
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Reporters
3
- VERSION = '1.1.6'
3
+ VERSION = '1.1.7'
4
4
  end
5
5
  end
data/test/test_helper.rb CHANGED
@@ -2,6 +2,7 @@ require "bundler/setup"
2
2
  require "minitest/autorun"
3
3
  require "minitest/reporters"
4
4
 
5
+ ENV['MINITEST_REPORTERS_MONO'] = 'yes'
5
6
  module MinitestReportersTest
6
7
  class TestCase < Minitest::Test
7
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-reporters
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest