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:



372
373
374
375
376
377
378
379
380
# File 'lib/minitest.rb', line 372

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.



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

def assertions
  @assertions
end

#countObject

The count of runnable methods ran.



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

def count
  @count
end

#ioObject

The IO used to report.



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

def io
  @io
end

#old_syncObject

:nodoc:



370
371
372
# File 'lib/minitest.rb', line 370

def old_sync
  @old_sync
end

#optionsObject

Command-line options for this run.



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

def options
  @options
end

#resultsObject

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



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

def results
  @results
end

#start_timeObject

The start time of the run.



368
369
370
# File 'lib/minitest.rb', line 368

def start_time
  @start_time
end

#syncObject

:nodoc:



370
371
372
# File 'lib/minitest.rb', line 370

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)


385
386
387
# File 'lib/minitest.rb', line 385

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.



420
421
422
423
424
425
426
427
428
429
430
# File 'lib/minitest.rb', line 420

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.



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
460
461
462
463
# File 'lib/minitest.rb', line 435

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.



393
394
395
396
397
398
399
# File 'lib/minitest.rb', line 393

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.



404
405
406
407
408
409
410
411
412
413
414
# File 'lib/minitest.rb', line 404

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