123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::Formatters::ExceptionPresenter::Factory Private

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Classes:
Inherits: Object
Defined in: rspec-core/lib/rspec/core/formatters/exception_presenter.rb

Overview

Configuring the ::RSpec::Core::Formatters::ExceptionPresenter with the right set of options to handle pending vs failed vs skipped and aggregated (or not) failures is not simple. This class takes care of building an appropriate ::RSpec::Core::Formatters::ExceptionPresenter for the provided example.

Class Method Summary

Instance Method Summary

Instance Method Details

#build

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 313

def build
  ExceptionPresenter.new(@exception, @example, options)
end

#multiple_exception_summarizer(exception, prior_detail_formatter, color) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 374

def multiple_exception_summarizer(exception, prior_detail_formatter, color)
  lambda do |example, colorizer|
    summary = if exception.[:hide_backtrace]
                # Since the backtrace is hidden, the subfailures will come
                # immediately after this, and using `:` will read well.
                "Got #{exception.exception_count_description}:"
              else
                # The backtrace comes after this, so using a `:` doesn't make sense
                # since the failures may be many lines below.
                "#{exception.summary}."
              end

    summary = colorizer.wrap(summary, color || RSpec.configuration.failure_color)
    return summary unless prior_detail_formatter
    [
      prior_detail_formatter.call(example, colorizer),
      summary
    ]
  end
end

#multiple_exceptions_error?(exception) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 370

def multiple_exceptions_error?(exception)
  MultipleExceptionError::InterfaceTag === exception
end

#options (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 329

def options
  with_multiple_error_options_as_needed(@exception, pending_options || {})
end

#pending_options (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 333

def pending_options
  if @execution_result.pending_fixed?
    {
      :description   => "#{@example.full_description} FIXED",
      :message_color => RSpec.configuration.fixed_color,
      :failure_lines => [
        "Expected pending '#{@execution_result.pending_message}' to fail. No error was raised."
      ]
    }
  elsif @execution_result.status == :pending
    options = {
      :message_color    => RSpec.configuration.pending_color,
      :detail_formatter => PENDING_DETAIL_FORMATTER
    }
    if RSpec.configuration.pending_failure_output == :no_backtrace
      options[:backtrace_formatter] = EmptyBacktraceFormatter
    end
    options
  end
end

#sub_failure_list_formatter(exception, message_color) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 395

def sub_failure_list_formatter(exception, message_color)
  common_backtrace_truncater = CommonBacktraceTruncater.new(exception)

  lambda do |failure_number, colorizer|
    FlatMap.flat_map(exception.all_exceptions.each_with_index) do |failure, index|
      options = with_multiple_error_options_as_needed(
        failure,
        :description             => nil,
        :indentation             => 0,
        :message_color           => message_color || RSpec.configuration.failure_color,
        :skip_shared_group_trace => true
      )

      failure   = common_backtrace_truncater.with_truncated_backtrace(failure)
      presenter = ExceptionPresenter.new(failure, @example, options)
      presenter.fully_formatted_lines(
        "#{failure_number ? "#{failure_number}." : ''}#{index + 1}",
        colorizer
      )
    end
  end
end

#with_multiple_error_options_as_needed(exception, options) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/formatters/exception_presenter.rb', line 354

def with_multiple_error_options_as_needed(exception, options)
  return options unless multiple_exceptions_error?(exception)

  options = options.merge(
    :failure_lines          => [],
    :extra_detail_formatter => sub_failure_list_formatter(exception, options[:message_color]),
    :detail_formatter       => multiple_exception_summarizer(exception,
                                                             options[:detail_formatter],
                                                             options[:message_color])
  )

  return options unless exception.[:hide_backtrace]
  options[:backtrace_formatter] = EmptyBacktraceFormatter
  options
end