class RSpec::Trace::Formatter

Public Instance Methods

example_failed(notification) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rspec/trace/formatter.rb, line 87
def stop(_notification)
  output.puts(JSON.dump({timestamp: current_timestamp, event: :stop}))
end

Private Instance Methods

completed_example_attributes(example) click to toggle source
# File lib/rspec/trace/formatter.rb, line 119
def completed_example_attributes(example)
  example_attributes(example).merge({
    result: example_execution_result_attributes(example.execution_result)
  })
end
current_time() click to toggle source
# File lib/rspec/trace/formatter.rb, line 129
def current_time
  if defined?(Timecop)
    Time.now_without_mock_time
  else
    Time.now
  end
end
current_timestamp() click to toggle source
# File lib/rspec/trace/formatter.rb, line 137
def current_timestamp
  format_time(current_time)
end
example_attributes(example) click to toggle source
# File lib/rspec/trace/formatter.rb, line 102
def example_attributes(example)
  {
    description: example.description,
    full_description: example.full_description,
    file_path: example.file_path,
    location: example.location
  }
end
example_execution_result_attributes(execution_result) click to toggle source
# File lib/rspec/trace/formatter.rb, line 111
def example_execution_result_attributes(execution_result)
  {
    status: execution_result.status,
    pending_message: execution_result.pending_message,
    pending_fixed: execution_result.pending_fixed
  }
end
example_group_attributes(example_group) click to toggle source
# File lib/rspec/trace/formatter.rb, line 93
def example_group_attributes(example_group)
  {
    description: example_group.description,
    described_class: example_group.described_class,
    file_path: example_group.file_path,
    location: example_group.location
  }
end
format_time(time) click to toggle source
# File lib/rspec/trace/formatter.rb, line 125
def format_time(time)
  time.xmlschema(3)
end