Exception: RSpec::Core::MultipleExceptionError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rspec/core/formatters/exception_presenter.rb

Overview

Provides a single exception instance that provides access to multiple sub-exceptions. This is used in situations where a single individual spec has multiple exceptions, such as one in the it block and one in an after block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*exceptions) ⇒ MultipleExceptionError

Returns a new instance of MultipleExceptionError.

Parameters:

  • exceptions (Array<Exception>)

    The initial list of exceptions.



513
514
515
516
517
518
519
520
521
522
523
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 513

def initialize(*exceptions)
  super()

  @failures                = []
  @other_errors            = []
  @all_exceptions          = []
  @aggregation_metadata    = { :hide_backtrace => true }
  @aggregation_block_label = nil

  exceptions.each { |e| add e }
end

Instance Attribute Details

#aggregation_block_labelnil (readonly)

Returns Provided only for interface compatibility with RSpec::Expectations::MultipleExpectationsNotMetError.

Returns:

  • (nil)

    Provided only for interface compatibility with RSpec::Expectations::MultipleExpectationsNotMetError.



510
511
512
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 510

def aggregation_block_label
  @aggregation_block_label
end

#aggregation_metadataHash (readonly)

Returns Metadata used by RSpec for formatting purposes.

Returns:

  • (Hash)

    Metadata used by RSpec for formatting purposes.



506
507
508
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 506

def 
  @aggregation_metadata
end

#all_exceptionsArray<Exception> (readonly)

Returns The list of failures and other exceptions, combined.

Returns:

  • (Array<Exception>)

    The list of failures and other exceptions, combined.



503
504
505
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 503

def all_exceptions
  @all_exceptions
end

#failuresArray<Exception> (readonly)

Returns The list of failures.

Returns:

  • (Array<Exception>)

    The list of failures.



497
498
499
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 497

def failures
  @failures
end

#other_errorsArray<Exception> (readonly)

Returns The list of other errors.

Returns:

  • (Array<Exception>)

    The list of other errors.



500
501
502
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 500

def other_errors
  @other_errors
end

Instance Method Details

#exception_count_descriptionvoid

return [String] A description of the failure/error counts.



538
539
540
541
542
543
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 538

def exception_count_description
  failure_count = Formatters::Helpers.pluralize(failures.size, "failure")
  return failure_count if other_errors.empty?
  error_count = Formatters::Helpers.pluralize(other_errors.size, "other error")
  "#{failure_count} and #{error_count}"
end

#messageString

Note:

RSpec does not actually use this -- instead it formats each exception individually.

Returns Combines all the exception messages into a single string.

Returns:

  • (String)

    Combines all the exception messages into a single string.



528
529
530
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 528

def message
  all_exceptions.map(&:message).join("\n\n")
end

#summaryString

Returns A summary of the failure, including the block label and a count of failures.

Returns:

  • (String)

    A summary of the failure, including the block label and a count of failures.



533
534
535
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 533

def summary
  "Got #{exception_count_description}"
end