RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter, but the BaseTextFormatter documents all of the notifications implemented as part of the standard interface. The reporter will issue these during a normal test suite run, but a formatter will only receive those notifications it has registered itself to receive.
@see RSpec::Core::Formatters::BaseTextFormatter @see RSpec::Core::Reporter
@api public
@param output [IO] the formatter output
# File lib/rspec/core/formatters/base_formatter.rb, line 24 def initialize(output) @output = output || StringIO.new @example_group = nil end
@api public
Invoked at the very end, `close` allows the formatter to clean up resources, e.g. open streams, etc.
@param notification [NullNotification]
# File lib/rspec/core/formatters/base_formatter.rb, line 151 def close(notification) restore_sync_output end
@api public
This method is invoked at the beginning of the execution of each example group.
The next method to be invoked after this is {#example_passed}, {#example_pending}, or {#example_group_finished}.
@param notification [GroupNotification] containing #example_group subclass of `RSpec::Core::ExampleGroup`
# File lib/rspec/core/formatters/base_formatter.rb, line 52 def example_group_started(notification) @example_group = notification.group end
@api public
This method is invoked before any examples are run, right after they have all been collected. This can be useful for special formatters that need to provide progress on feedback (graphical ones).
This will only be invoked once, and the next one to be invoked is {#example_group_started}.
@param notification [StartNotification]
# File lib/rspec/core/formatters/base_formatter.rb, line 39 def start(notification) start_sync_output @example_count = notification.count end
# File lib/rspec/core/formatters/base_formatter.rb, line 165 def output_supports_sync output.respond_to?(:sync=) end
# File lib/rspec/core/formatters/base_formatter.rb, line 161 def restore_sync_output output.sync = @old_sync if output_supports_sync and !output.closed? end
# File lib/rspec/core/formatters/base_formatter.rb, line 157 def start_sync_output @old_sync, output.sync = output.sync, true if output_supports_sync end