module Minitest

Constants

DEFAULT_REPORTER

Public Class Methods

default_reporter(options) click to toggle source

Create default composite reporter.

Some reporters take no arguments, some take just ‘options` and others take `io` and `options`, so the length of the method parameters is used to determine which arguments to use.

# File lib/minitest/reporter_api.rb, line 50
def self.default_reporter(options)
  reporter = CompositeReporter.new
  defaults = [self.reporter || DEFAULT_REPORTER].flatten
  defaults.each do |rpt|
    reporter << (
      case rpt
      when Class
        params = rpt.instance_method(:initialize).parameters
        case params.size #arity
        when 0 then rpt.new
        when 1 then 
          if params == [[:rest]]  # best guess
            rpt.new(options[:io], options)
          else
            rpt.new(options)
          end
        else rpt.new(options[:io], options)
        end
      else
        rpt
      end
    )
  end
  reporter
end
run(args = []) click to toggle source

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.

# File lib/minitest/reporter_api.rb, line 24
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 if VERSION > "5.0.8"
  reporter.report

  reporter.passed?
end