123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::Formatters::BaseFormatter

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
BaseTextFormatter, RSpec::Core::Formatters::BisectDebugFormatter, RSpec::Core::Formatters::BisectProgressFormatter, RSpec::Core::Formatters::DocumentationFormatter, RSpec::Core::Formatters::FailureListFormatter, RSpec::Core::Formatters::HtmlFormatter, RSpec::Core::Formatters::JsonFormatter, RSpec::Core::Formatters::ProgressFormatter
Inherits: Object
Defined in: rspec-core/lib/rspec/core/formatters/base_formatter.rb

Overview

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(output) ⇒ BaseFormatter

Parameters:

  • output (IO)

    the formatter output

See Also:

  • RSpec::Core::Formatters::Protocol#initialize
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 23

def initialize(output)
  @output = output || StringIO.new
  @example_group = nil
end

Instance Attribute Details

#example_group (rw)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 17

attr_accessor :example_group

#output (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 18

attr_reader :output

Instance Method Details

#close(_notification)

Parameters:

  • _notification (NullNotification)

    (Ignored)

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 50

def close(_notification)
  restore_sync_output
end

#example_group_started(notification)

Parameters:

  • notification (GroupNotification)

    containing example_group subclass of ‘RSpec::Core::ExampleGroup`

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 42

def example_group_started(notification)
  @example_group = notification.group
end

#output_supports_sync (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 64

def output_supports_sync
  output.respond_to?(:sync=)
end

#restore_sync_output (private)

[ GitHub ]

  
# File 'rspec-core/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(notification)

Parameters:

  • notification (StartNotification)

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/base_formatter.rb', line 32

def start(notification)
  start_sync_output
  @example_count = notification.count
end

#start_sync_output (private)

[ GitHub ]

  
# File 'rspec-core/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