class RSpec::Core::Formatters::BaseFormatter

@see RSpec::Core::Reporter
@see RSpec::Core::Formatters::BaseTextFormatter
only receive those notifications it has registered itself to receive.
interface. The reporter will issue these during a normal test suite run, but a formatter will
but the BaseTextFormatter documents all of the notifications implemented as part of the standard
RSpec’s built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter,

def close(notification)

Other tags:
    Api: - public
def close(notification)
  restore_sync_output
end

def color_enabled?

def color_enabled?
  configuration.color_enabled?(output)
end

def configuration

def configuration
  RSpec.configuration
end

def example_failed(notification)

Returns:
  • (Array) -

Parameters:
  • example () -- instance of subclass of `RSpec::Core::ExampleGroup`

Other tags:
    Api: - public
def example_failed(notification)
  @failed_examples << notification.example
end

def example_group_started(notification)

Parameters:
  • example_group () --
  • example_group () -- subclass of `RSpec::Core::ExampleGroup`

Other tags:
    Api: - public
def example_group_started(notification)
  @example_group = notification.group
end

def example_pending(notification)

Returns:
  • (Array) -

Parameters:
  • example () -- instance of subclass of `RSpec::Core::ExampleGroup`
def example_pending(notification)
  @pending_examples << notification.example
end

def example_started(notification)

Returns:
  • (Array) -

Parameters:
  • example () -- instance of subclass of `RSpec::Core::ExampleGroup`

Other tags:
    Api: - public
def example_started(notification)
  examples << notification.example
end

def fail_fast?

def fail_fast?
  configuration.fail_fast
end

def find_failed_line(backtrace, path)

def find_failed_line(backtrace, path)
  path = File.expand_path(path)
  backtrace.detect { |line|
    match = line.match(/(.+?):(\d+)(|:\d+)/)
    match && match[1].downcase == path.downcase
  }
end

def format_backtrace(backtrace, example)

Other tags:
    Api: - public
def format_backtrace(backtrace, example)
  configuration.backtrace_formatter.format_backtrace(backtrace, example.metadata)
end

def initialize(output)

Parameters:
  • output () --

Other tags:
    Api: - public
def initialize(output)
  @output = output || StringIO.new
  @example_count = @pending_count = @failure_count = 0
  @examples = []
  @failed_examples = []
  @pending_examples = []
  @example_group = nil
end

def mute_profile_output?(failure_count)

def mute_profile_output?(failure_count)
  # Don't print out profiled info if there are failures and `--fail-fast` is used, it just clutters the output
  !profile_examples? || (fail_fast? && failure_count != 0)
end

def output_supports_sync

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

def profile_examples?

def profile_examples?
  configuration.profile_examples
end

def read_failed_line(exception, example)

def read_failed_line(exception, example)
  unless matching_line = find_failed_line(exception.backtrace, example.file_path)
    return "Unable to find matching line from backtrace"
  end
  file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
  if File.exist?(file_path)
    File.readlines(file_path)[line_number.to_i - 1] ||
      "Unable to find matching line in #{file_path}"
  else
    "Unable to find #{file_path} to read failed line"
  end
rescue SecurityError
  "Unable to read failed line"
end

def restore_sync_output

def restore_sync_output
  output.sync = @old_sync if output_supports_sync and !output.closed?
end

def slowest_examples

Other tags:
    Api: - private
def slowest_examples
  number_of_examples = RSpec.configuration.profile_examples
  sorted_examples = examples.sort_by {|example|
    example.execution_result[:run_time] }.reverse.first(number_of_examples)
  total, slows = [examples, sorted_examples].map do |exs|
    exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }
  end
  {:examples => sorted_examples, :total => total, :slows => slows}
end

def slowest_groups

Other tags:
    Api: - private
def slowest_groups
  number_of_examples = RSpec.configuration.profile_examples
  example_groups = {}
  examples.each do |example|
    location = example.example_group.parent_groups.last.metadata[:example_group][:location]
    example_groups[location] ||= Hash.new(0)
    example_groups[location][:total_time]  += example.execution_result[:run_time]
    example_groups[location][:count]       += 1
    example_groups[location][:description] = example.example_group.top_level_description unless example_groups[location].has_key?(:description)
  end
  # stop if we've only one example group
  return {} if example_groups.keys.length <= 1
  example_groups.each_value do |hash|
    hash[:average] = hash[:total_time].to_f / hash[:count]
  end
  example_groups.sort_by {|_, hash| -hash[:average]}.first(number_of_examples)
end

def start(notification)

Parameters:
  • example_count () --

Other tags:
    Api: - public
def start(notification)
  start_sync_output
  @example_count = notification.count
end

def start_sync_output

def start_sync_output
  @old_sync, output.sync = output.sync, true if output_supports_sync
end