Class: Polyrun::Reporting::RspecFailureFragmentFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrun/reporting/rspec_failure_fragment_formatter.rb

Overview

RSpec formatter: appends one JSON object per failed example to the shard fragment file. Enable via Polyrun::RSpec.install_failure_fragments! and POLYRUN_FAILURE_FRAGMENTS=1 (set by run-shards –merge-failures).

Output: tmp/polyrun_failures/polyrun-failure-fragment-<workerN|shardM-workerN>.jsonl (same basename rules as Coverage::CollectorFragmentMeta.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ RspecFailureFragmentFormatter

Returns a new instance of RspecFailureFragmentFormatter.



16
17
18
19
# File 'lib/polyrun/reporting/rspec_failure_fragment_formatter.rb', line 16

def initialize(output)
  @output = output
  @path = fragment_path
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



14
15
16
# File 'lib/polyrun/reporting/rspec_failure_fragment_formatter.rb', line 14

def output
  @output
end

Instance Method Details

#example_failed(notification) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/polyrun/reporting/rspec_failure_fragment_formatter.rb', line 26

def example_failed(notification)
  ex = notification.example
  exc = notification.exception
  row = {
    "id" => ex.id,
    "full_description" => ex.full_description,
    "location" => ex.location,
    "file_path" => ex.file_path,
    "line_number" => example_line_number(ex),
    "message" => exc.message.to_s,
    "exception_class" => exc.class.name,
    "polyrun_shard_index" => ENV["POLYRUN_SHARD_INDEX"],
    "polyrun_shard_total" => ENV["POLYRUN_SHARD_TOTAL"],
    "polyrun_shard_matrix_index" => matrix_env_or_nil("POLYRUN_SHARD_MATRIX_INDEX"),
    "polyrun_shard_matrix_total" => matrix_env_or_nil("POLYRUN_SHARD_MATRIX_TOTAL"),
    "rspec_seed" => seed_if_known,
    "rspec_order" => order_if_known
  }
  trim_backtrace!(row, exc)
  File.open(@path, "a") { |f| f.puts(JSON.generate(row.compact)) }
end

#start(_notification) ⇒ Object



21
22
23
24
# File 'lib/polyrun/reporting/rspec_failure_fragment_formatter.rb', line 21

def start(_notification)
  FileUtils.mkdir_p(File.dirname(@path))
  File.write(@path, "")
end