Module: RSpec::Core::MultipleExceptionError::InterfaceTag

Included in:
RSpec::Core::MultipleExceptionError
Defined in:
lib/rspec/core/formatters/exception_presenter.rb

Overview

Used so there is a common module in the ancestor chain of this class and `RSpec::Expectations::MultipleExpectationsNotMetError`, which allows code to detect exceptions that are instances of either, without first checking to see if rspec-expectations is loaded.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(ex) ⇒ Object

Provides a way to force `ex` to be something that satisfies the multiple exception error interface. If it already satisfies it, it will be returned; otherwise it will wrap it in a `MultipleExceptionError`.



438
439
440
441
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 438

def self.for(ex)
  return ex if self === ex
  MultipleExceptionError.new(ex)
end

Instance Method Details

#add(exception) ⇒ Object

Appends the provided exception to the list.

Parameters:

  • exception (Exception)

    Exception to append to the list.



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 412

def add(exception)
  # `PendingExampleFixedError` can be assigned to an example that initially has no
  # failures, but when the `aggregate_failures` around hook completes, it notifies of
  # a failure. If we do not ignore `PendingExampleFixedError` it would be surfaced to
  # the user as part of a multiple exception error, which is undesirable. While it's
  # pretty weird we handle this here, it's the best solution I've been able to come
  # up with, and `PendingExampleFixedError` always represents the _lack_ of any exception
  # so clearly when we are transitioning to a `MultipleExceptionError`, it makes sense to
  # ignore it.
  return if Pending::PendingExampleFixedError === exception

  return if exception == self

  all_exceptions << exception

  if exception.class.name =~ /RSpec/
    failures << exception
  else
    other_errors << exception
  end
end