Class: Bulldogger::Minitest::Reporter

Inherits:
Minitest::AbstractReporter
  • Object
show all
Defined in:
lib/bulldogger/integrations/minitest.rb

Overview

Turns one finished test into a Bulldogger evidence file. Registered into Minitest's CompositeReporter, so #record runs once per test method, pass or fail. Minitest.run_one_method always returns a Minitest::Result, never the Test instance itself, so the test's id/file/line come from Result's own klass/name/source_location rather than from re-deriving them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = $stdout) ⇒ Reporter

AbstractReporter#initialize takes no arguments; this reporter keeps its own io so #annotate! can print to it directly instead of depending on the failure's own #message reaching the runner's output. A Rails-wrapped Minitest 6 run proved that dependency false: Rails' SuppressedSummaryReporter skips the deferred failure printout, and its own inline reporter runs before this one, so a rewritten #message never surfaces anywhere.



55
56
57
58
# File 'lib/bulldogger/integrations/minitest.rb', line 55

def initialize(io = $stdout)
  super()
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



46
47
48
# File 'lib/bulldogger/integrations/minitest.rb', line 46

def io
  @io
end

Instance Method Details

#prerecord(_klass, _name) ⇒ Object



60
61
62
63
64
65
# File 'lib/bulldogger/integrations/minitest.rb', line 60

def prerecord(_klass, _name)
  Bulldogger::FramesCollector.begin_test if defined?(Bulldogger::FramesCollector)
  Bulldogger::FltCollector.begin_test if defined?(Bulldogger::FltCollector)
  Bulldogger::ExecCollector.begin_test if defined?(Bulldogger::ExecCollector)
  Minitest.instance.begin_test
end

#record(result) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bulldogger/integrations/minitest.rb', line 67

def record(result)
  failure = result.failure
  return if failure.nil? || result.skipped?

  exception = exception_for(failure)
  path = Minitest.instance.record_failure(exception: exception, test: test_for(result))
  annotate!(failure, path) if path
ensure
  Minitest.instance.end_test
  Bulldogger::FramesCollector.end_test if defined?(Bulldogger::FramesCollector)
  Bulldogger::FltCollector.end_test if defined?(Bulldogger::FltCollector)
  Bulldogger::ExecCollector.end_test if defined?(Bulldogger::ExecCollector)
end