Module: Mutineer::MinitestIntegration::OuterReporter

Defined in:
lib/mutineer/minitest_integration/outer_reporter.rb

Overview

Finds the outer reporter of a Minitest run, for the hooks that act only on the run's own results. A test can build a reporter of its own and record on it, or start a nested run, so the first reporter the run hands to its suites is the one that counts. Child-process only, like MinitestIntegration.

A client module extends Client, registers here, and sets its armed pid. The hook then gives the outer reporter to each client armed in this process. Minitest 5 and 6 need different hook points; an unknown shape gets no hook.

Defined Under Namespace

Modules: Client, Hook5, Hook6

Class Method Summary collapse

Class Method Details

.clients ⇒ Array<Module>

The registered clients, in registration order.

Returns:

  • (Array<Module>)


77
78
79
# File 'lib/mutineer/minitest_integration/outer_reporter.rb', line 77

def clients
  @clients ||= []
end

.hook_for_loaded_minitest ⇒ Module?

The outer-reporter hook for the loaded Minitest.

Returns:

  • (Module, nil) —

    Hook6, Hook5, or nil for an unknown shape.



103
104
105
106
107
108
109
110
# File 'lib/mutineer/minitest_integration/outer_reporter.rb', line 103

def hook_for_loaded_minitest
  runnable = ::Minitest::Runnable
  if ::Minitest.respond_to?(:run_all_suites) && runnable.respond_to?(:run_suite)
    Hook6
  elsif ::Minitest.respond_to?(:__run) && runnable.respond_to?(:run_one_method)
    Hook5
  end
end

.prepend_once(target, mod) ⇒ void

This method returns an undefined value.

Prepends mod on target once. A copy on a superclass does not count, because it comes after the own methods of target.

Parameters:

  • target (Module) —

    the class or singleton class.

  • mod (Module) —

    the module to prepend.



118
119
120
121
122
# File 'lib/mutineer/minitest_integration/outer_reporter.rb', line 118

def prepend_once(target, mod)
  return if target.ancestors.take_while { |a| !a.equal?(target) }.include?(mod)

  target.prepend(mod)
end

.register(client) ⇒ void

This method returns an undefined value.

Registers a client once.

Parameters:

  • client (Module) —

    a module that extends Client.



85
86
87
# File 'lib/mutineer/minitest_integration/outer_reporter.rb', line 85

def register(client)
  clients << client unless clients.include?(client)
end

.seen(reporter) ⇒ void

This method returns an undefined value.

Gives reporter to every client armed in this process that has no outer reporter yet.

Parameters:

  • reporter (Minitest::CompositeReporter) —

    a reporter a run uses.



94
95
96
97
98
# File 'lib/mutineer/minitest_integration/outer_reporter.rb', line 94

def seen(reporter)
  clients.each do |client|
    client.armed_reporter ||= reporter if client.armed_here?
  end
end