Module: Minitest

Defined in:
lib/minitest/reporter_api.rb

Constant Summary collapse

DEFAULT_REPORTER =
[SummaryReporter, ProgressReporter]

Class Method Summary collapse

Class Method Details

.default_reporter(options) ⇒ Object

Create default composite reporter.

Unfortunately some reporters take no arguments, some take just ‘options` and others take `io` and `options`, so the arity is used to determine which arguments to use.



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

def self.default_reporter(options)
  reporter = CompositeReporter.new
  defaults = [self.reporter || DEFAULT_REPORTER].flatten
  defaults.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
  reporter
end

.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.



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

def self.run args = []
  self.load_plugins

  options = process_args args

  reporter = default_reporter(options) 

  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 rescue nil
  reporter.report

  reporter.passed?
end