Class: RSpec::Core::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/reporter.rb

Overview

A reporter will send notifications to listeners, usually formatters for the spec suite run.

Constant Summary

Instance Method Summary (collapse)

Constructor Details

- (Reporter) initialize(configuration)

Returns a new instance of Reporter

14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rspec/core/reporter.rb', line 14
def initialize(configuration)
  @configuration = configuration
  @listeners = Hash.new { |h, k| h[k] = Set.new }
  @examples = []
  @failed_examples = []
  @pending_examples = []
  @duration = @start = @load_time = nil
  @non_example_exception_count = 0
  @setup_default = lambda {}
  @setup = false
end

Instance Method Details

- (void) message(message)

Send a custom message to supporting formatters.

Parameters:

  • message (#to_s)

    A message object to send to formatters

96
97
98
# File 'lib/rspec/core/reporter.rb', line 96
def message(message)
  notify :message, Notifications::MessageNotification.new(message)
end

- (void) publish(event, options = {})

Publish a custom event to supporting registered formatters.

Parameters:

  • event (Symbol)

    Name of the custom event to trigger on formatters

  • options (Hash) (defaults to: {})

    Hash of arguments to provide via CustomNotification

See Also:

105
106
107
108
109
110
111
# File 'lib/rspec/core/reporter.rb', line 105
def publish(event, options={})
  if RSPEC_NOTIFICATIONS.include? event
    raise "RSpec::Core::Reporter#publish is intended for sending custom " \
          "events not internal RSpec ones, please rename your custom event."
  end
  notify event, Notifications::CustomNotification.for(options)
end

- (void) register_listener(listener, *notifications)

Registers a listener to a list of notifications. The reporter will send notification of events to all registered listeners.

Parameters:

  • listener (Object)

    An obect that wishes to be notified of reporter events

  • notifications (Array)

    Array of symbols represents the events a listener wishes to subscribe too

42
43
44
45
46
47
# File 'lib/rspec/core/reporter.rb', line 42
def register_listener(listener, *notifications)
  notifications.each do |notification|
    @listeners[notification.to_sym] << listener
  end
  true
end

- (void) report(count, &block) - (void) report(count, &block)

Initializes the report run and yields itself for further reporting. The block is required, so that the reporter can manage cleaning up after the run.

Examples:


reporter.report(group.examples.size) do |r|
  example_groups.map {|g| g.run(r) }
end

Parameters:

  • expected_example_count (Integer)

    the number of examples being run

Yields:

  • (Block)

    block yields itself for further reporting.

76
77
78
79
80
81
82
83
# File 'lib/rspec/core/reporter.rb', line 76
def report(expected_example_count)
  start(expected_example_count)
  begin
    yield self
  ensure
    finish
  end
end