class RSpec::MultiprocessRunner::ReportingFormatter

RSpec formatter used by workers to communicate spec execution to the coordinator.

@private

Attributes

worker[RW]

The worker to which to report spec status. This has to be a class-level attribute because you can't access the formatter instance used by RSpec's runner.

Public Class Methods

new(*ignored_args) click to toggle source
Calls superclass method
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 29
def initialize(*ignored_args)
  super(StringIO.new)
  @current_example_groups = []
end

Public Instance Methods

example_failed(notification) click to toggle source
Calls superclass method
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 53
def example_failed(notification)
  details = capture_output { super(notification) }
  report_example_result(
    :failed,
    notification.example,
    notification.fully_formatted(1)
  )
end
example_group_finished(example_group) click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 40
def example_group_finished(example_group)
  @current_example_groups.pop
end
example_group_started(notification) click to toggle source
Calls superclass method
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 34
def example_group_started(notification)
  super(notification)

  @current_example_groups.push(notification.group.description.strip)
end
example_passed(notification) click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 44
def example_passed(notification)
  report_example_result(:passed, notification.example)
end
example_pending(notification) click to toggle source
Calls superclass method
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 48
def example_pending(notification)
  details = capture_output { super(notification) }
  report_example_result(:pending, notification.example, details)
end
message(struct) click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 62
def message(struct)
  # this is just for reporting errors not otherwise reported
  return unless RSpec.world.non_example_failure

  message = struct.message
  # skip these as they always come after an error is seems
  return if message =~ /^No examples found./

  worker.report_error(message)
end

Private Instance Methods

capture_output() { || ... } click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 75
def capture_output
  output.string = ""
  yield
  captured = output.string
  output.string = ""
  captured
end
current_example_description(example) click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 87
def current_example_description(example)
  (@current_example_groups + [example.description.strip]).join('ยท')
end
report_example_result(example_status, example, details=nil) click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 91
def report_example_result(example_status, example, details=nil)
  description = current_example_description(example)
  line = example.metadata[:line_number]
  worker.report_example_result(example_status, description, line, details)
end
worker() click to toggle source
# File lib/rspec/multiprocess_runner/reporting_formatter.rb, line 83
def worker
  self.class.worker
end