class RSpec::Expectations::MultipleExpectationsNotMetError

Exception raised from `aggregate_failures` when multiple expectations fail.

@note The constant is defined here but the extensive logic of this class

is lazily defined when `FailureAggregator` is autoloaded, since we do
not need to waste time defining that functionality unless
`aggregate_failures` is used.

Exception raised from `aggregate_failures` when multiple expectations fail.

Attributes

all_exceptions[R]

@return [Array<Exception>] The list of expectation failures and other exceptions, combined.

Public Class Methods

new(failure_aggregator) click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 136
def initialize(failure_aggregator)
  @failure_aggregator = failure_aggregator
  @all_exceptions = failures + other_errors
end

Public Instance Methods

aggregation_block_label() click to toggle source

@return [String] The user-assigned label for the aggregation block.

# File lib/rspec/expectations/failure_aggregator.rb, line 111
def aggregation_block_label
  @failure_aggregator.block_label
end
aggregation_metadata() click to toggle source

@return [Hash] The metadata hash passed to `aggregate_failures`.

# File lib/rspec/expectations/failure_aggregator.rb, line 116
def aggregation_metadata
  @failure_aggregator.metadata
end
exception_count_description() click to toggle source

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

# File lib/rspec/expectations/failure_aggregator.rb, line 127
def exception_count_description
  failure_count = pluralize("failure", failures.size)
  return failure_count if other_errors.empty?
  error_count = pluralize("other error", other_errors.size)
  "#{failure_count} and #{error_count}"
end
failures() click to toggle source

@return [Array<RSpec::Expectations::ExpectationNotMetError>] The list of expectation failures.

# File lib/rspec/expectations/failure_aggregator.rb, line 98
def failures
  @failure_aggregator.failures
end
message() click to toggle source

@return [String] The fully formatted exception message.

# File lib/rspec/expectations/failure_aggregator.rb, line 93
def message
  @message ||= (["#{summary}:"] + enumerated_failures + enumerated_errors).join("\n\n")
end
other_errors() click to toggle source

@return [Array<Exception>] The list of other exceptions.

# File lib/rspec/expectations/failure_aggregator.rb, line 103
def other_errors
  @failure_aggregator.other_errors
end
summary() click to toggle source

@return [String] A summary of the failure, including the block label and a count of failures.

# File lib/rspec/expectations/failure_aggregator.rb, line 121
def summary
  "Got #{exception_count_description} from failure aggregation "          "block#{block_description}"
end

Private Instance Methods

block_description() click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 141
def block_description
  return "" unless aggregation_block_label
  " #{aggregation_block_label.inspect}"
end
enumerated(exceptions, index_offset) { |exception| ... } click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 150
def enumerated(exceptions, index_offset)
  exceptions.each_with_index.map do |exception, index|
    index += index_offset
    formatted_message = yield exception
    "#{index_label index}#{indented formatted_message, index}"
  end
end
enumerated_errors() click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 162
def enumerated_errors
  enumerated(other_errors, failures.size) do |error|
    "#{error.class}: #{error.message}"
  end
end
enumerated_failures() click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 158
def enumerated_failures
  enumerated(failures, 0, &:message)
end
indentation() click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 177
def indentation
  @indentation ||= ' ' * longest_index_label_width
end
indented(failure_message, index) click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 168
def indented(failure_message, index)
  line_1, *rest = failure_message.strip.lines.to_a
  first_line_indentation = ' ' * (longest_index_label_width - width_of_label(index))

  first_line_indentation + line_1 + rest.map do |line|
    line =~ /\S/ ? indentation + line : line
  end.join
end
index_label(index) click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 189
def index_label(index)
  "  #{index + 1}) "
end
longest_index_label_width() click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 181
def longest_index_label_width
  @longest_index_label_width ||= width_of_label(failures.size)
end
pluralize(noun, count) click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 146
def pluralize(noun, count)
  "#{count} #{noun}#{'s' unless count == 1}"
end
width_of_label(index) click to toggle source
# File lib/rspec/expectations/failure_aggregator.rb, line 185
def width_of_label(index)
  index_label(index).chars.count
end