class RSpec::Core::Formatters::ExceptionPresenter

@private

Constants

PENDING_DETAIL_FORMATTER

@private

Attributes

Public Class Methods

# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 16
def initialize(exception, example, options={})
  @exception               = exception
  @example                 = example
  @message_color           = options.fetch(:message_color)          { RSpec.configuration.failure_color }
  @description             = options.fetch(:description)            { example.full_description }
  @detail_formatter        = options.fetch(:detail_formatter)       { Proc.new {} }
  @extra_detail_formatter  = options.fetch(:extra_detail_formatter) { Proc.new {} }
  @backtrace_formatter     = options.fetch(:backtrace_formatter)    { RSpec.configuration.backtrace_formatter }
  @indentation             = options.fetch(:indentation, 2)
  @skip_shared_group_trace = options.fetch(:skip_shared_group_trace, false)
  @failure_lines           = options[:failure_lines]
end

Public Instance Methods

# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 78
def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  formatted_backtrace.map do |backtrace_info|
    colorizer.wrap "# #{backtrace_info}", RSpec.configuration.detail_color
  end
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 33
def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  add_shared_group_lines(failure_lines, colorizer).map do |line|
    colorizer.wrap line, message_color
  end
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 39
def formatted_backtrace(exception=@exception)
  backtrace_formatter.format_backtrace(exception.backtrace, example.metadata) +
    formatted_cause(exception)
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 45
def formatted_cause(exception)
  last_cause = final_exception(exception, [exception])
  cause = []

  if exception.cause
    cause << '------------------'
    cause << '--- Caused by: ---'
    cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/

    encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
      cause << "  #{line}"
    end

    unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
      lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
      lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace # rubocop:disable Metrics/BlockNesting

      lines.each do |line|
        cause << ("  #{line}")
      end
    end
  end

  cause
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 84
def fully_formatted(failure_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  lines = fully_formatted_lines(failure_number, colorizer)
  lines.join("\n") << "\n"
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 89
def fully_formatted_lines(failure_number, colorizer)
  lines = [
    encoded_description(description),
    detail_formatter.call(example, colorizer),
    formatted_message_and_backtrace(colorizer),
    extra_detail_formatter.call(failure_number, colorizer),
  ].compact.flatten

  lines = indent_lines(lines, failure_number)
  lines.unshift("")
  lines
end
# File rspec-core/lib/rspec/core/formatters/exception_presenter.rb, line 29
def message_lines
  add_shared_group_lines(failure_lines, Notifications::NullColorizer)
end