Class: Minitest::Reporter

Inherits:
Object show all
Defined in:
lib/minitest.rb,
lib/minitest/parallel_each.rb

Overview

Collects and reports the result of all runs.

Direct Known Subclasses

CompositeReporter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = $stdout, options = {}) ⇒ Reporter

:nodoc:



368
369
370
371
372
373
374
375
376
# File 'lib/minitest.rb', line 368

def initialize io = $stdout, options = {} # :nodoc:
  self.io      = io
  self.options = options

  self.assertions = 0
  self.count      = 0
  self.results    = []
  self.start_time = nil
end

Instance Attribute Details

#assertionsObject

The count of assertions run.



339
340
341
# File 'lib/minitest.rb', line 339

def assertions
  @assertions
end

#countObject

The count of runnable methods ran.



344
345
346
# File 'lib/minitest.rb', line 344

def count
  @count
end

#ioObject

The IO used to report.



349
350
351
# File 'lib/minitest.rb', line 349

def io
  @io
end

#old_syncObject

:nodoc:



366
367
368
# File 'lib/minitest.rb', line 366

def old_sync
  @old_sync
end

#optionsObject

Command-line options for this run.



354
355
356
# File 'lib/minitest.rb', line 354

def options
  @options
end

#resultsObject

The results of all the runs. (Non-passing only to cut down on memory)



359
360
361
# File 'lib/minitest.rb', line 359

def results
  @results
end

#start_timeObject

The start time of the run.



364
365
366
# File 'lib/minitest.rb', line 364

def start_time
  @start_time
end

#syncObject

:nodoc:



366
367
368
# File 'lib/minitest.rb', line 366

def sync
  @sync
end

Class Method Details

.synchronizeObject

:nodoc:



91
92
93
94
95
96
97
# File 'lib/minitest/parallel_each.rb', line 91

def self.synchronize # :nodoc:
  if @mutex then # see parallel_each.rb
    @mutex.synchronize { yield }
  else
    yield
  end
end

Instance Method Details

#passed?Boolean

Did this run pass?

Returns:

  • (Boolean)


381
382
383
# File 'lib/minitest.rb', line 381

def passed?
  results.all?(&:skipped?)
end

#record(result) ⇒ Object

Record a result and output the Runnable#result_code. Stores the result of the run if the run did not pass.



416
417
418
419
420
421
422
423
424
425
426
# File 'lib/minitest.rb', line 416

def record result
  self.count += 1
  self.assertions += result.assertions

  io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
  options[:verbose]
  io.print result.result_code
  io.puts if options[:verbose]

  results << result if not result.passed? or result.skipped?
end

#reportObject

Outputs the summary of the run.



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/minitest.rb', line 431

def report
  aggregate = results.group_by { |r| r.failure.class }
  aggregate.default = [] # dumb. group_by should provide this

  f = aggregate[Assertion].size
  e = aggregate[UnexpectedError].size
  s = aggregate[Skip].size
  t = Time.now - start_time

  io.puts # finish the dots
  io.puts
  io.puts "Finished in %.6fs, %.4f runs/s, %.4f assertions/s." %
    [t, count / t, self.assertions / t]

  format = "%d runs, %d assertions, %d failures, %d errors, %d skips"
  summary = format % [count, self.assertions, f, e, s]

  filtered_results = results.dup
  filtered_results.reject!(&:skipped?) unless options[:verbose]

  filtered_results.each_with_index do |result, i|
    io.puts "\n%3d) %s" % [i+1, result]
  end

  io.puts
  io.puts summary

  io.sync = self.old_sync if self.sync
end

#run_and_reportObject

Top-level method to ensure that start and report are called. Yields to the caller.



389
390
391
392
393
394
395
# File 'lib/minitest.rb', line 389

def run_and_report
  start

  yield

  report
end

#simple_recordObject

Record a result and output the Runnable#result_code. Stores the result of the run if the run did not pass.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/minitest/parallel_each.rb', line 99

def record result
  self.count += 1
  self.assertions += result.assertions

  io.print "%s#%s = %.2f s = " % [result.class, result.name, result.time] if
  options[:verbose]
  io.print result.result_code
  io.puts if options[:verbose]

  results << result if not result.passed? or result.skipped?
end

#startObject

Starts reporting on the run.



400
401
402
403
404
405
406
407
408
409
410
# File 'lib/minitest.rb', line 400

def start
  self.sync = io.respond_to? :"sync=" # stupid emacs
  self.old_sync, io.sync = io.sync, true if self.sync

  self.start_time = Time.now

  io.puts "Run options: #{options[:args]}"
  io.puts
  io.puts "# Running:"
  io.puts
end