minitest-reporters 1.1.11 → 1.1.12

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: 88d6126ca997acbf677b531e44849c74d37af66b
4
- data.tar.gz: 24a96027c20c449926bbf346989d99ad7353c81d
3
+ metadata.gz: f9a13367d73b48623e2124cd6cfcfdfeab4e50e6
4
+ data.tar.gz: df4d8a09132fd4f992641f0958d4d7682930fd65
5
5
  SHA512:
6
- metadata.gz: 3e9f3a0c9a8245b1ff5b1d0767c635aa88410129cc601d8d9e2bfb4384227c084ceb4e902dae25dc961c7a27a934b3687ac6762dd1d3a47fbbb0e7be1ed2da66
7
- data.tar.gz: d66a69f5e620abdb0ac9ea4b762ece8220e8a248b36badb681a6a79c9d9aa3f8d8762ae545bfd120b76dc8d363a57bade6dc0d5f663dfb914fa9719f81d4cb9e
6
+ metadata.gz: 8337e7a82318d409675b9907ed60aa979bd7fc3658ab107bc330433555465d97da0f778b8ae7edacbba01369c5579ea0f80d3a56302617fc0f2d829fac1c2e7e
7
+ data.tar.gz: 2eb20439c9528c2aaa1d07c2bca1e404b9cd3bf78b29ffbb86e80ed9bef4ac980c2f62542621c0923b915566e3c0069f1873c318ad7237b8b8f2ba55fa418842
@@ -148,10 +148,10 @@ module Minitest
148
148
  order_sorted_body.each_with_object([]) do |result, obj|
149
149
  rating = rate(result[:last], result[:min], result[:max])
150
150
 
151
- obj << "#{avg_label} #{result[:avg]} " \
152
- "#{min_label} #{result[:min]} " \
153
- "#{max_label} #{result[:max]} " \
154
- "#{run_label(rating)} #{result[:last]} " \
151
+ obj << "#{avg_label} #{result[:avg].to_s.ljust(12)} " \
152
+ "#{min_label} #{result[:min].to_s.ljust(12)} " \
153
+ "#{max_label} #{result[:max].to_s.ljust(12)} " \
154
+ "#{run_label(rating)} #{result[:last].to_s.ljust(12)} " \
155
155
  "#{des_label} #{result[:desc]}\n"
156
156
  end.join
157
157
  end
@@ -177,10 +177,10 @@ module Minitest
177
177
  size = Array(timings).size
178
178
  sum = Array(timings).inject { |total, x| total + x }
179
179
  obj << {
180
- avg: (sum / size).round(9).to_s.ljust(12),
181
- min: Array(timings).min.round(9).to_s.ljust(12),
182
- max: Array(timings).max.round(9).to_s.ljust(12),
183
- last: Array(timings).last.round(9).to_s.ljust(12),
180
+ avg: (sum / size).round(9),
181
+ min: Array(timings).min.round(9),
182
+ max: Array(timings).max.round(9),
183
+ last: Array(timings).last.round(9),
184
184
  desc: description,
185
185
  }
186
186
  end.sort_by { |k| k[sort_column] }
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module Reporters
3
- VERSION = '1.1.11'
3
+ VERSION = '1.1.12'
4
4
  end
5
5
  end
@@ -0,0 +1,152 @@
1
+ require_relative "../../test_helper"
2
+
3
+ module MinitestReportersTest
4
+ class MeanTimeReporterUnitTest < Minitest::Test
5
+ def setup
6
+ configure_report_paths
7
+ previous_test_run
8
+ end
9
+
10
+ def teardown
11
+ File.delete(@previous_run_path) if File.exist?(@previous_run_path)
12
+ File.delete(@report_file_path) if File.exist?(@report_file_path)
13
+ end
14
+
15
+ def test_sorts_avg_numerically
16
+ report_output = generate_report(:avg)
17
+
18
+ expected_order = [
19
+ 'AVG_SLOW',
20
+ 'MAX_SLOW',
21
+ 'MIN_SLOW',
22
+ 'MIDDLE',
23
+ 'MIN_FAST',
24
+ 'MAX_FAST',
25
+ 'AVG_FAST'
26
+ ]
27
+ verify_result_order(report_output, expected_order)
28
+ end
29
+
30
+ def test_sorts_min_numerically
31
+ report_output = generate_report(:min)
32
+
33
+ expected_order = [
34
+ 'MIN_SLOW',
35
+ 'AVG_SLOW',
36
+ 'MAX_SLOW',
37
+ 'MIDDLE',
38
+ 'MAX_FAST',
39
+ 'AVG_FAST',
40
+ 'MIN_FAST'
41
+ ]
42
+ verify_result_order(report_output, expected_order)
43
+ end
44
+
45
+ def test_sorts_max_numerically
46
+ report_output = generate_report(:max)
47
+
48
+ expected_order = [
49
+ 'MAX_SLOW',
50
+ 'AVG_SLOW',
51
+ 'MIN_SLOW',
52
+ 'MIDDLE',
53
+ 'MIN_FAST',
54
+ 'AVG_FAST',
55
+ 'MAX_FAST'
56
+ ]
57
+ verify_result_order(report_output, expected_order)
58
+ end
59
+
60
+ def test_sorts_last_numerically
61
+ report_output = generate_report(:last)
62
+
63
+ expected_order = [
64
+ 'AVG_SLOW',
65
+ 'MIN_SLOW',
66
+ 'MAX_SLOW',
67
+ 'MIDDLE',
68
+ 'MIN_FAST',
69
+ 'MAX_FAST',
70
+ 'AVG_FAST'
71
+ ]
72
+ verify_result_order(report_output, expected_order)
73
+ end
74
+
75
+ private
76
+
77
+ def simulate_suite_runtime(suite_name, run_time)
78
+ test_suite = Minitest::Test.new(suite_name)
79
+ base_clock_time = Minitest::Reporters.clock_time
80
+ Minitest::Reporters.stub(:clock_time, base_clock_time - run_time) do
81
+ @reporter.before_suite(test_suite)
82
+ end
83
+ @reporter.after_suite(test_suite)
84
+ end
85
+
86
+ def previous_test_run
87
+ @reporter = Minitest::Reporters::MeanTimeReporter.new(
88
+ previous_runs_filename: @previous_run_path,
89
+ report_filename: @report_file_path
90
+ )
91
+
92
+ simulate_suite_runtime('MIDDLE', 5.0)
93
+ simulate_suite_runtime('MIN_FAST', 0.5)
94
+ simulate_suite_runtime('MIN_SLOW', 10.5)
95
+ simulate_suite_runtime('MAX_FAST', 1.2)
96
+ simulate_suite_runtime('MAX_SLOW', 16.3)
97
+ simulate_suite_runtime('AVG_FAST', 1.3)
98
+ simulate_suite_runtime('AVG_SLOW', 10.2)
99
+ @reporter.tests << Minitest::Test.new('Final')
100
+ # Generate a "previous" run
101
+ @reporter.io = StringIO.new
102
+ @reporter.start
103
+ @reporter.report
104
+ end
105
+
106
+ def configure_report_paths
107
+ previous_runs_file = Tempfile.new('minitest-mean-time-previous-runs')
108
+ previous_runs_file.close
109
+ @previous_run_path = previous_runs_file.path
110
+ previous_runs_file.delete
111
+ report_file = Tempfile.new('minitest-mean-time-report')
112
+ report_file.close
113
+ @report_file_path = report_file.path
114
+ report_file.delete
115
+ end
116
+
117
+ def generate_report(sort_column)
118
+ # Reset the reporter for the test run
119
+ @reporter = Minitest::Reporters::MeanTimeReporter.new(
120
+ previous_runs_filename: @previous_run_path,
121
+ report_filename: @report_file_path,
122
+ sort_column: sort_column
123
+ )
124
+ simulate_suite_runtime('MIDDLE', 5.0)
125
+ simulate_suite_runtime('MIN_FAST', 3.5)
126
+ simulate_suite_runtime('MIN_SLOW', 10.5)
127
+ simulate_suite_runtime('MAX_FAST', 0.9)
128
+ simulate_suite_runtime('MAX_SLOW', 6.3)
129
+ simulate_suite_runtime('AVG_FAST', 0.65)
130
+ simulate_suite_runtime('AVG_SLOW', 14.2)
131
+ @reporter.tests << Minitest::Test.new('Final')
132
+
133
+ report_output = StringIO.new
134
+ @reporter.io = report_output
135
+ @reporter.start
136
+ @reporter.report
137
+ report_output
138
+ end
139
+
140
+ def verify_result_order(report_output, expected_order)
141
+ report_output.rewind
142
+ test_lines = report_output.read.split("\n")
143
+ test_lines.select! { |line| line.start_with?('Avg:') }
144
+
145
+ # Exclude the final placeholder 0 second test from assertions
146
+ test_lines.reject! { |line| line.end_with?('Minitest::Test') }
147
+ actual_order = test_lines.map { |line| line.gsub(/.*Description: /, '') }
148
+
149
+ assert_equal(expected_order, actual_order, "\n#{test_lines.join("\n")}")
150
+ end
151
+ end
152
+ 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.11
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-30 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -143,6 +143,7 @@ files:
143
143
  - test/integration/reporters/progress_reporter_test.rb
144
144
  - test/test_helper.rb
145
145
  - test/unit/minitest/extensible_backtrace_filter_test.rb
146
+ - test/unit/minitest/mean_time_reporter_unit_test.rb
146
147
  - test/unit/minitest/minitest_reporter_plugin_test.rb
147
148
  - test/unit/minitest/reporters_test.rb
148
149
  - test/unit/minitest/spec_reporter_test.rb