class RSpec::Core::Formatters::ExceptionPresenter::Factory
provided example.
This class takes care of building an appropriate ‘ExceptionPresenter` for the
pending vs failed vs skipped and aggregated (or not) failures is not simple.
Configuring the `ExceptionPresenter` with the right set of options to handle
@private
def build
def build ExceptionPresenter.new(@exception, @example, options) end
def initialize(example)
def initialize(example) @example = example @execution_result = example.execution_result @exception = if @execution_result.status == :pending @execution_result.pending_exception else @execution_result.exception end end
def multiple_exception_summarizer(exception, prior_detail_formatter, color)
def multiple_exception_summarizer(exception, prior_detail_formatter, color) lambda do |example, colorizer| summary = if exception.aggregation_metadata[: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
def multiple_exceptions_error?(exception)
def multiple_exceptions_error?(exception) MultipleExceptionError::InterfaceTag === exception end
def options
def options with_multiple_error_options_as_needed(@exception, pending_options || {}) end
def pending_options
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 { :message_color => RSpec.configuration.pending_color, :detail_formatter => PENDING_DETAIL_FORMATTER } end end
def sub_failure_list_formatter(exception, message_color)
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
def with_multiple_error_options_as_needed(exception, options)
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.aggregation_metadata[:hide_backtrace] options[:backtrace_formatter] = EmptyBacktraceFormatter options end