Class: Bulldogger::Evidence

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldogger/evidence.rb

Overview

Writes stored failure data and links valid replay evidence. Capture and Replay own runtime observation; this class does not observe it.

The exception's message and backtrace are read here, at report time, not inside the :raise hook. Exception#backtrace can still be nil when :raise fires -- Ruby fills it in as the exception unwinds -- so reading it from the hook would record less than what a test framework's own failure report already has by the time it calls record_failure.

Constant Summary collapse

SLUG_MAX_LENGTH =
80

Instance Method Summary collapse

Constructor Details

#initialize(config:, run:, capture:, replay: nil) ⇒ Evidence

Returns a new instance of Evidence.



20
21
22
23
24
25
# File 'lib/bulldogger/evidence.rb', line 20

def initialize(config:, run:, capture:, replay: nil)
  @config = config
  @run = run
  @capture = capture
  @replay = replay
end

Instance Method Details

#record_failure(exception:, test:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bulldogger/evidence.rb', line 27

def record_failure(exception:, test:)
  # A disabled switch means "wrote nothing" -- not "wrote an empty
  # missed record". Writing capture_mode: missed here would mean
  # a user who turned this off still gets a run directory and a
  # frames_unavailable_reason, which reads as "tried and failed"
  # rather than "did not run", the opposite of what they asked for.
  return nil unless @config.enabled
  return nil if exception.nil?

  path = @run.next_path(slug_for(test))
  payload = build_payload(exception: exception, test: test)
  result = @replay&.call(test: test, run_dir: File.dirname(path), frames: payload["frames"])
  attach_replay(payload, result)
  File.write(path, "#{JSON.pretty_generate(payload)}\n")
  @run.record(path, test: payload["test"], exception_summary: payload["exception"].slice("class", "message"))
  path
end