Class: RSpec::Core::Reporter

### Home Classes Methods

### In Files

- lib/rspec/core/reporter.rb

### Parent

Object

### Methods

- ::new
- #deprecation
- #example_failed
- #example_group_finished
- #example_group_started
- #example_passed
- #example_pending
- #example_started
- #finish
- #message
- #notify
- #register_listener
- #registered_listeners
- #report
- #reset
- #start
- #stop

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::AnonymousExampleGroup
- RSpec::Core::Backports
- RSpec::Core::Backports::Random
- RSpec::Core::Backports::Random::Implementation
- RSpec::Core::Backports::Random::MT19937
- RSpec::Core::BacktraceFormatter
- RSpec::Core::Configuration
- RSpec::Core::Configuration::DeprecationReporterBuffer
- RSpec::Core::Configuration::ExposeCurrentExample
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::DRbOptions
- RSpec::Core::DRbRunner
- RSpec::Core::DSL
- RSpec::Core::DSL::RSpec
- RSpec::Core::Example
- RSpec::Core::Example::ExecutionResult
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::ExclusionRules
- RSpec::Core::FilterManager
- RSpec::Core::FilterRules
- RSpec::Core::FilterableItemRepository
- RSpec::Core::FilterableItemRepository::QueryOptimized
- RSpec::Core::FilterableItemRepository::UpdateOptimized
- RSpec::Core::FlatMap
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::ConsoleCodes
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DeprecationFormatter::DelayedPrinter
- RSpec::Core::Formatters::DeprecationFormatter::FileStream
- RSpec::Core::Formatters::DeprecationFormatter::ImmediatePrinter
- RSpec::Core::Formatters::DeprecationFormatter::RaiseErrorStream
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::Loader
- RSpec::Core::Formatters::ProfileFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::Protocol
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::CoderayConverter
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::HashImitatable
- RSpec::Core::HashImitatable::ClassMethods
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterContextHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollections
- RSpec::Core::InclusionRules
- RSpec::Core::LegacyExampleGroupHash
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::After
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::Before
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleGroupHash
- RSpec::Core::Metadata::ExampleHash
- RSpec::Core::Metadata::HashPopulator
- RSpec::Core::MetadataFilter
- RSpec::Core::MinitestAssertionsAdapter
- RSpec::Core::MockingAdapters
- RSpec::Core::MockingAdapters::Flexmock
- RSpec::Core::MockingAdapters::Mocha
- RSpec::Core::MockingAdapters::Null
- RSpec::Core::MockingAdapters::RR
- RSpec::Core::MockingAdapters::RSpec
- RSpec::Core::Notifications
- RSpec::Core::Notifications::DeprecationNotification
- RSpec::Core::Notifications::ExampleNotification
- RSpec::Core::Notifications::ExamplesNotification
- RSpec::Core::Notifications::FailedExampleNotification
- RSpec::Core::Notifications::NullColorizer
- RSpec::Core::Notifications::NullNotification
- RSpec::Core::Notifications::PendingExampleFailedAsExpectedNotification
- RSpec::Core::Notifications::PendingExampleFixedNotification
- RSpec::Core::Notifications::PendingExampleNotificationMethods
- RSpec::Core::Notifications::ProfileNotification
- RSpec::Core::Notifications::SeedNotification
- RSpec::Core::Notifications::SkippedExampleNotification
- RSpec::Core::Notifications::SummaryNotification
- RSpec::Core::NullReporter
- RSpec::Core::Ordering
- RSpec::Core::Ordering::ConfigurationManager
- RSpec::Core::Ordering::Custom
- RSpec::Core::Ordering::Identity
- RSpec::Core::Ordering::Random
- RSpec::Core::Ordering::Registry
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::Pending::SkipDeclaredInExample
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::RandomNumberGenerator
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::Sandbox
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::SharedExampleGroupInclusionStackFrame
- RSpec::Core::SharedExampleGroupModule
- RSpec::Core::SuiteHookContext
- RSpec::Core::TestUnitAssertionsAdapter
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::Warnings
- RSpec::Core::World
- RSpec::ExampleGroups
- Object

No matching classes.

# RSpec::Core::Reporter

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

### Attributes

examples[R]

@private

failed_examples[R]

@private

pending_examples[R]

@private

### Public Class Methods

new(configuration) click to toggle source

    # File lib/rspec/core/reporter.rb, line 5
    def initialize(configuration)
      @configuration = configuration
      @listeners = Hash.new { |h, k| h[k] = Set.new }
      @examples = []
      @failed_examples = []
      @pending_examples = []
      @duration = @start = @load_time = nil
    end

### Public Instance Methods

deprecation(hash) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 115
    def deprecation(hash)
      notify :deprecation, Notifications::DeprecationNotification.from_hash(hash)
    end

example_failed(example) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 103
    def example_failed(example)
      @failed_examples << example
      notify :example_failed, Notifications::ExampleNotification.for(example)
    end

example_group_finished(group) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 87
    def example_group_finished(group)
      notify :example_group_finished, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
    end

example_group_started(group) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 82
    def example_group_started(group)
      notify :example_group_started, Notifications::GroupNotification.new(group) unless group.descendant_filtered_examples.empty?
    end

example_passed(example) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 98
    def example_passed(example)
      notify :example_passed, Notifications::ExampleNotification.for(example)
    end

example_pending(example) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 109
    def example_pending(example)
      @pending_examples << example
      notify :example_pending, Notifications::ExampleNotification.for(example)
    end

example_started(example) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 92
    def example_started(example)
      @examples << example
      notify :example_started, Notifications::ExampleNotification.for(example)
    end

finish() click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 120
    def finish
      stop
      notify :start_dump,    Notifications::NullNotification
      notify :dump_pending,  Notifications::ExamplesNotification.new(self)
      notify :dump_failures, Notifications::ExamplesNotification.new(self)
      notify :deprecation_summary, Notifications::NullNotification
      unless mute_profile_output?
        notify :dump_profile, Notifications::ProfileNotification.new(@duration, @examples,
                                                                     @configuration.profile_examples)
      end
      notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
                                                                   @pending_examples, @load_time)
      notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
    ensure
      notify :close, Notifications::NullNotification
    end

message(message) click to toggle source

@private

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

notify(event, notification) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 144
    def notify(event, notification)
      registered_listeners(event).each do |formatter|
        formatter.__send__(event, notification)
      end
    end

register_listener(listener, *notifications) click to toggle source

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

@param listener [Object] An obect that wishes to be notified of reporter

    events

@param notifications [Array] Array of symbols represents the events a

    listener wishes to subscribe too

    # File lib/rspec/core/reporter.rb, line 31
    def register_listener(listener, *notifications)
      notifications.each do |notification|
        @listeners[notification.to_sym] << listener
      end
      true
    end

registered_listeners(notification) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 39
    def registered_listeners(notification)
      @listeners[notification].to_a
    end

report(expected_example_count) click to toggle source

@api @overload report(count, &block) @overload report(count, &block) @param expected_example_count [Integer] the number of examples being run @yield [Block] block yields itself for further reporting.

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.

@example

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

    # File lib/rspec/core/reporter.rb, line 59
    def report(expected_example_count)
      start(expected_example_count)
      begin
        yield self
      ensure
        finish
      end
    end

reset() click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 18
    def reset
      @examples = []
      @failed_examples = []
      @pending_examples = []
    end

start(expected_example_count, time=RSpec::Core::Time.now) click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 69
    def start(expected_example_count, time=RSpec::Core::Time.now)
      @start = time
      @load_time = (@start - @configuration.start_time).to_f
      notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
      notify :start, Notifications::StartNotification.new(expected_example_count, @load_time)
    end

stop() click to toggle source

@private

    # File lib/rspec/core/reporter.rb, line 138
    def stop
      @duration = (RSpec::Core::Time.now - @start).to_f if @start
      notify :stop, Notifications::ExamplesNotification.new(self)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.