Class: RSpec::Core::Reporter
- Inherits:
-
Object
- Object
- RSpec::Core::Reporter
- Defined in:
- lib/rspec/core/reporter.rb
Overview
A reporter will send notifications to listeners, usually formatters for the spec suite run.
Instance Method Summary collapse
-
#exit_early(exit_code) ⇒ void
Reports a run that exited early without having run any examples.
-
#initialize(configuration) ⇒ Reporter
constructor
A new instance of Reporter.
-
#message(message) ⇒ void
Send a custom message to supporting formatters.
-
#publish(event, options = {}) ⇒ void
Publish a custom event to supporting registered formatters.
-
#register_listener(listener, *notifications) ⇒ void
Registers a listener to a list of notifications.
-
#report(expected_example_count) {|Block| ... } ⇒ void
Initializes the report run and yields itself for further reporting.
Constructor Details
#initialize(configuration) ⇒ Reporter
Returns a new instance of Reporter.
14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 @profiler = nil end |
Instance Method Details
#exit_early(exit_code) ⇒ void
Reports a run that exited early without having run any examples.
84 85 86 |
# File 'lib/rspec/core/reporter.rb', line 84 def exit_early(exit_code) report(0) { exit_code } end |
#message(message) ⇒ void
Send a custom message to supporting formatters.
99 100 101 |
# File 'lib/rspec/core/reporter.rb', line 99 def () notify :message, Notifications::MessageNotification.new() end |
#publish(event, options = {}) ⇒ void
Publish a custom event to supporting registered formatters.
108 109 110 111 112 113 114 |
# File 'lib/rspec/core/reporter.rb', line 108 def publish(event, ={}) 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() end |
#register_listener(listener, *notifications) ⇒ void
Registers a listener to a list of notifications. The reporter will send notification of events to all registered listeners.
37 38 39 40 41 42 |
# File 'lib/rspec/core/reporter.rb', line 37 def register_listener(listener, *notifications) notifications.each do |notification| @listeners[notification.to_sym] << listener end true end |
#report(count, &block) ⇒ void #report(count, &block) ⇒ void
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.
71 72 73 74 75 76 77 78 |
# File 'lib/rspec/core/reporter.rb', line 71 def report(expected_example_count) start(expected_example_count) begin yield self ensure finish end end |