class RSpec::Core::Formatters::ExceptionPresenter::Factory
@private Configuring the ‘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 `ExceptionPresenter` for the provided example.
Public Class Methods
new(example)
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 291 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
Public Instance Methods
build()
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 285 def build ExceptionPresenter.new(@exception, @example, options) end
Private Instance Methods
multiple_exception_summarizer(exception, prior_detail_formatter, color)
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 342 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
multiple_exceptions_error?(exception)
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 338 def multiple_exceptions_error?(exception) MultipleExceptionError::InterfaceTag === exception end
options()
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 301 def options with_multiple_error_options_as_needed(@exception, pending_options || {}) end
pending_options()
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 305 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
sub_failure_list_formatter(exception, message_color)
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 363 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)
click to toggle source
# File lib/rspec/core/formatters/exception_presenter.rb, line 322 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