Class: RSpecTelemetry::Formatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/rspec_telemetry/formatter.rb

Instance Method Summary collapse

Instance Method Details

#close(_notification) ⇒ Object



67
68
69
# File 'lib/rspec_telemetry/formatter.rb', line 67

def close(_notification)
  RSpecTelemetry.safely("formatter#close") { RSpecTelemetry.finish! }
end

#dump_summary(notification) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rspec_telemetry/formatter.rb', line 54

def dump_summary(notification)
  RSpecTelemetry.safely("formatter#dump_summary") do
    recorder.record(
      "suite.finished",
      example_id: nil,
      duration_ms: (notification.duration * 1000.0).round(3),
      example_count: notification.example_count,
      failure_count: notification.failure_count,
      pending_count: notification.pending_count
    )
  end
end

#example_finished(notification) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rspec_telemetry/formatter.rb', line 40

def example_finished(notification)
  RSpecTelemetry.safely("formatter#example_finished") do
    example = notification.example
    # Flush per-example aggregates (sql.group) before example.finished so
    # they land inside the example's event block, like factory events do.
    RSpecTelemetry.flush_example_events!
    record_example_finished(example) if config.capture_examples
    recorder.flush
  ensure
    # Avoid attributing after(:suite) or later work to the last example.
    recorder.clear_current_example
  end
end

#example_started(notification) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec_telemetry/formatter.rb', line 23

def example_started(notification)
  RSpecTelemetry.safely("formatter#example_started") do
    example = notification.example
    # Runs before before(:each), so FactoryBot calls inside hooks get this example_id.
    recorder.set_current_example(example.id)
    @gc_before = config.capture_gc ? GcSample.take : nil
    next unless config.capture_examples

    recorder.record(
      "example.started",
      file_path: example.file_path,
      line_number: example.[:line_number],
      full_description: example.full_description
    )
  end
end

#start(_notification) ⇒ Object



19
20
21
# File 'lib/rspec_telemetry/formatter.rb', line 19

def start(_notification)
  RSpecTelemetry.safely("formatter#start") { RSpecTelemetry.start! }
end