Exception: RSpec::Core::MultipleExceptionError

Inherits:
StandardError
  • Object
show all
Includes:
InterfaceTag
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.

Defined Under Namespace

Modules: InterfaceTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InterfaceTag

#add, for

Constructor Details

#initialize(*exceptions) ⇒ MultipleExceptionError



463
464
465
466
467
468
469
470
471
472
473
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 463

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)



460
461
462
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 460

def aggregation_block_label
  @aggregation_block_label
end

#aggregation_metadataHash (readonly)



456
457
458
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 456

def 
  @aggregation_metadata
end

#all_exceptionsArray<Exception> (readonly)



453
454
455
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 453

def all_exceptions
  @all_exceptions
end

#failuresArray<Exception> (readonly)



447
448
449
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 447

def failures
  @failures
end

#other_errorsArray<Exception> (readonly)



450
451
452
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 450

def other_errors
  @other_errors
end

Instance Method Details

#exception_count_descriptionObject

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



488
489
490
491
492
493
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 488

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.



478
479
480
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 478

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

#summaryString



483
484
485
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 483

def summary
  "Got #{exception_count_description}"
end