Class: RSpec::Trace::Formatter

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

Direct Known Subclasses

OpenTelemetryFormatter

Instance Method Summary collapse

Instance Method Details

#example_failed(notification) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rspec/trace/formatter.rb', line 74

def example_failed(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_failed,
    example: completed_example_attributes(notification.example),
    exception: {
      message: notification.example.exception.message,
      type: notification.example.exception.class.name,
      backtrace: notification.example.exception.full_message(highlight: false, order: :top).encode("UTF-8", invalid: :replace, undef: :replace, replace: "")
    }
  }))
end

#example_group_finished(notification) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rspec/trace/formatter.rb', line 42

def example_group_finished(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_group_finished,
    group: example_group_attributes(notification.group)
  }))
end

#example_group_started(notification) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/rspec/trace/formatter.rb', line 34

def example_group_started(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_group_started,
    group: example_group_attributes(notification.group)
  }))
end

#example_passed(notification) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/rspec/trace/formatter.rb', line 58

def example_passed(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_passed,
    example: completed_example_attributes(notification.example)
  }))
end

#example_pending(notification) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/rspec/trace/formatter.rb', line 66

def example_pending(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_pending,
    example: completed_example_attributes(notification.example)
  }))
end

#example_started(notification) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rspec/trace/formatter.rb', line 50

def example_started(notification)
  output.puts(JSON.dump({
    timestamp: current_timestamp,
    event: :example_started,
    example: example_attributes(notification.example)
  }))
end

#start(notification) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/trace/formatter.rb', line 21

def start(notification)
  start_time = current_time
  output.puts(JSON.dump({
    timestamp: format_time(start_time - notification.load_time.seconds),
    event: :initiated
  }))
  output.puts(JSON.dump({
    timestamp: format_time(start_time),
    event: :start,
    count: notification.count
  }))
end

#stop(_notification) ⇒ Object



87
88
89
# File 'lib/rspec/trace/formatter.rb', line 87

def stop(_notification)
  output.puts(JSON.dump({timestamp: current_timestamp, event: :stop}))
end