Module: Minitest

Defined in:
lib/minitest/reporter_api.rb

Class Method Summary collapse

Class Method Details

.run(args = []) ⇒ Object

Modify Minitest’s run method to check for code configured reporters. This allows reporters to be configured in test helper scripts. e.g.

Minitest.reporter = MyReporter.new

If just the class is given, it will work as well.

Minitest.reporter = MyReporter

More than one reporter can be used by setting reporter to an array.

Minitest.reporter = [Minitest::SummaryReporter, MyReporter.new]

This definition is identical to Minitest’s with the exception of the ‘if self.reporter` condition.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/minitest/reporter_api.rb', line 20

def self.run args = []
  self.load_plugins

  options = process_args args

  if self.reporter
    reporter = setup_reporters(self.reporter, options)
  else
    reporter = CompositeReporter.new
    reporter << SummaryReporter.new(options[:io], options)
    reporter << ProgressReporter.new(options[:io], options)
  end

  self.reporter = reporter # this makes it available to plugins
  self.init_plugins options
  self.reporter = nil # runnables shouldn't depend on the reporter, ever

  reporter.start
  __run reporter, options
  self.parallel_executor.shutdown
  reporter.report

  reporter.passed?
end

.setup_reporters(reporters, options) ⇒ Object

Initialize reporters, if need be, and add to ‘reporter` property.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/minitest/reporter_api.rb', line 48

def self.setup_reporters(reporters, options)
  reporter = CompositeReporter.new
  [reporters].flatten.each do |rpt|
    reporter << (
      case rpt
      when Class
        case rpt.method(:new).arity
        when 0 then rpt.new
        when 1, -1 then rpt.new(options)
        else rpt.new(options[:io], options)
        end
      else
        rpt
      end
    )
  end
  return reporter
end