Class: Minitest::Display::Reporter

Inherits:
Reporter
  • Object
show all
Defined in:
lib/minitest/display.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Reporter

Returns a new instance of Reporter.



142
143
144
145
146
147
148
# File 'lib/minitest/display.rb', line 142

def initialize(*args)
  super
  @total_assertions = 0
  @total_errors = 0
  @total_failures = 0
  @total_tests = 0
end

Instance Method Details

#display_slow_suitesObject



224
225
226
227
228
229
230
# File 'lib/minitest/display.rb', line 224

def display_slow_suites
  times = @test_times.map { |suite, tests| [suite, tests.map(&:last).inject {|sum, n| sum + n }] }.sort { |a, b| b[1] <=> a[1] }
  puts "Slowest suites:"
  times[0..display.options[:output_slow_suites].to_i].each do |suite, time|
    puts "%.2f s\t#{suite.name.gsub(/%/, '%%')}" % time
  end
end

#display_slow_testsObject



216
217
218
219
220
221
222
# File 'lib/minitest/display.rb', line 216

def display_slow_tests
  times = @test_times.values.flatten(1).sort { |a, b| b[1] <=> a[1] }
  puts "Slowest tests:"
  times[0..display.options[:output_slow].to_i].each do |test_name, time|
    puts "%.2f s\t#{test_name.gsub(/%/, '%%')}" % time
  end
end

#record(result) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/minitest/display.rb', line 183

def record(result)
  suite = result.class
  if suite != @current_suite
    record_suite_finished(@current_suite) if @current_suite
    record_suite_started(suite)
    @assertions = 0
  end
  @assertions += result.assertions
  @total_assertions += result.assertions
  @total_tests += 1
  output = if result.error?
    @total_errors += 1
    display.color(display.options[:print][:error], :error)
  elsif result.failure
    @total_failures += 1
    display.color(display.options[:print][:failure], :failure)
  else
    display.color(display.options[:print][:success], :success)
  end

  print output

  @wrap_count -= 1
  if @wrap_count == 0
    print "\n#{' ' * @suite_header.length}#{display.options[:suite_divider]}"
    @wrap_count = @wrap_at
  end

  run_recorder_method(:record, suite, result.name, result.assertions, result.time, result.failure)
  @test_times[suite] << ["#{suite}##{result.name}", result.time]
  @current_suite = suite
end

#record_suite_finished(suite) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/minitest/display.rb', line 161

def record_suite_finished(suite)
  @suite_finished = Time.now
  time = @suite_finished.to_f - @suite_started.to_f
  print "\n#{' ' * @suite_header.length}#{display.options[:suite_divider]}"
  print "%.2f s" % time
  run_recorder_method(:record_suite_finished, suite, @assertions, time)
end

#record_suite_started(suite) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'lib/minitest/display.rb', line 150

def record_suite_started(suite)
  if display.options[:suite_names] && display.printable_suite?(suite)
    @suite_header = suite.to_s
    print display.color("\n#{@suite_header}#{display.options[:suite_divider]}", :suite)
    @wrap_at = display.options[:wrap_at] - @suite_header.length
    @wrap_count = @wrap_at
  end
  @suite_started = Time.now
  run_recorder_method(:record_suite_started, suite)
end

#reportObject



175
176
177
178
179
180
181
# File 'lib/minitest/display.rb', line 175

def report
  record_suite_finished(@current_suite) if @current_suite
  puts
  display_slow_tests if display.options[:output_slow]
  display_slow_suites if display.options[:output_slow_suites]
  run_recorder_method(:record_tests_finished, @total_tests, @total_assertions, @total_failures, @total_errors, Time.now.to_f - @tests_started)
end

#startObject



169
170
171
172
173
# File 'lib/minitest/display.rb', line 169

def start
  @test_times ||= Hash.new { |h, k| h[k] = [] }
  @tests_started = Time.now.to_f
  run_recorder_method(:record_tests_started)
end