Class: SpecForge::Forge::Runner::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge/runner/reporter.rb

Overview

RSpec formatter listener for tracking test results

Receives notifications from RSpec when examples pass or fail, updating the forge's statistics and display accordingly.

Instance Method Summary collapse

Constructor Details

#initialize(forge = nil) ⇒ Reporter

Creates a new reporter for the given forge instance

Parameters:

  • forge (Forge, nil) (defaults to: nil)

    The forge instance to report to



20
21
22
23
24
# File 'lib/spec_forge/forge/runner/reporter.rb', line 20

def initialize(forge = nil)
  @forge = forge
  @stats = forge&.stats
  @display = forge&.display
end

Instance Method Details

#example_failed(notification) ⇒ void

This method returns an undefined value.

Called when an RSpec example fails

Parameters:

  • notification (RSpec::Core::Notifications::ExampleNotification)

    The failure notification



33
34
35
36
37
38
# File 'lib/spec_forge/forge/runner/reporter.rb', line 33

def example_failed(notification)
  return if @stats.nil? || @display.nil?

  @stats[:failed] += 1
  @display.expectation_failed(notification.example.description, indent: 1)
end

#example_passed(notification) ⇒ void

This method returns an undefined value.

Called when an RSpec example passes

Parameters:

  • notification (RSpec::Core::Notifications::ExampleNotification)

    The success notification



47
48
49
50
51
52
# File 'lib/spec_forge/forge/runner/reporter.rb', line 47

def example_passed(notification)
  return if @stats.nil? || @display.nil?

  @stats[:passed] += 1
  @display.expectation_passed(notification.example.description, indent: 1)
end