class RSpec::Core::Formatters::BaseFormatter

RSpec’s built-in formatters are all subclasses of RSpec::Core::Formatters::BaseFormatter.

@see RSpec::Core::Formatters::BaseTextFormatter @see RSpec::Core::Reporter @see RSpec::Core::Formatters::Protocol

Attributes

example_group[RW]
output[R]

Public Class Methods

new(output) click to toggle source

@api public @param output [IO] the formatter output @see RSpec::Core::Formatters::Protocol#initialize

# File lib/rspec/core/formatters/base_formatter.rb, line 23
def initialize(output)
  @output = output || StringIO.new
  @example_group = nil
end

Public Instance Methods

close(_notification) click to toggle source

@api public

@param _notification [NullNotification] (Ignored) @see RSpec::Core::Formatters::Protocol#close

# File lib/rspec/core/formatters/base_formatter.rb, line 50
def close(_notification)
  restore_sync_output
end
example_group_started(notification) click to toggle source

@api public

@param notification [GroupNotification] containing example_group

subclass of `RSpec::Core::ExampleGroup`

@see RSpec::Core::Formatters::Protocol#example_group_started

# File lib/rspec/core/formatters/base_formatter.rb, line 42
def example_group_started(notification)
  @example_group = notification.group
end
start(notification) click to toggle source

@api public

@param notification [StartNotification] @see RSpec::Core::Formatters::Protocol#start

# File lib/rspec/core/formatters/base_formatter.rb, line 32
def start(notification)
  start_sync_output
  @example_count = notification.count
end

Private Instance Methods

output_supports_sync() click to toggle source
# File lib/rspec/core/formatters/base_formatter.rb, line 64
def output_supports_sync
  output.respond_to?(:sync=)
end
restore_sync_output() click to toggle source
# File lib/rspec/core/formatters/base_formatter.rb, line 60
def restore_sync_output
  output.sync = @old_sync if output_supports_sync && !output.closed?
end
start_sync_output() click to toggle source
# File lib/rspec/core/formatters/base_formatter.rb, line 56
def start_sync_output
  @old_sync, output.sync = output.sync, true if output_supports_sync
end