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



61
62
63
# File 'lib/rspec_telemetry/formatter.rb', line 61

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

#dump_summary(notification) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rspec_telemetry/formatter.rb', line 48

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



37
38
39
40
41
42
43
44
45
46
# File 'lib/rspec_telemetry/formatter.rb', line 37

def example_finished(notification)
  RSpecTelemetry.safely("formatter#example_finished") do
    example = notification.example
    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



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

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)
    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



17
18
19
# File 'lib/rspec_telemetry/formatter.rb', line 17

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