Exception: RSpec::Expectations::MultipleExpectationsNotMetError
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
ExpectationNotMetError ,
Exception
|
|
Instance Chain:
self,
ExpectationNotMetError ,
Exception
|
|
Inherits: |
RSpec::Expectations::ExpectationNotMetError
|
Defined in: | rspec-expectations/lib/rspec/expectations.rb, rspec-expectations/lib/rspec/expectations/failure_aggregator.rb |
Overview
Exception raised from aggregate_failures
when multiple expectations fail.
Class Method Summary
- .new(failure_aggregator) ⇒ MultipleExpectationsNotMetError constructor private
Instance Attribute Summary
- #all_exceptions ⇒ Array<Exception> readonly
Instance Method Summary
- #aggregation_block_label ⇒ String
- #aggregation_metadata ⇒ Hash
-
#exception_count_description
return [String] A description of the failure/error counts.
- #failures ⇒ Array<RSpec::Expectations::ExpectationNotMetError>
- #message ⇒ String
- #other_errors ⇒ Array<Exception>
- #summary ⇒ String
- #backtrace_line(line) private
- #block_description private
- #enumerated(exceptions, index_offset) private
- #enumerated_errors private
- #enumerated_failures private
- #exclusion_patterns private
- #format_backtrace(backtrace) private
- #indentation private
- #indented(failure_message, index) private
- #index_label(index) private
- #longest_index_label_width private
- #pluralize(noun, count) private
- #width_of_label(index) private
Constructor Details
.new(failure_aggregator) ⇒ MultipleExpectationsNotMetError
(private)
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 160
def initialize(failure_aggregator) @failure_aggregator = failure_aggregator @all_exceptions = failures + other_errors end
Instance Attribute Details
#all_exceptions ⇒ Array
<Exception
> (readonly)
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 132
attr_reader :all_exceptions
Instance Method Details
#aggregation_block_label ⇒ String
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 135
def aggregation_block_label @failure_aggregator.block_label end
#aggregation_metadata ⇒ Hash
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 140
def @failure_aggregator. end
#backtrace_line(line) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 192
def backtrace_line(line) return if [Regexp.union(RSpec::CallerFilter::IGNORE_REGEX, *exclusion_patterns)].any? { |p| line =~ p } # It changes the current path that is relative to # system root to be relative to the project root. line.sub(/(\A|\s)#{File. ('.')}(#{File::SEPARATOR}|\s|\Z)/, '\\1.\\2'.freeze).sub(/\A([^:]+:\d+)$/, '\\1'.freeze) end
#block_description (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 165
def block_description return "" unless aggregation_block_label " #{aggregation_block_label.inspect}" end
#enumerated(exceptions, index_offset) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 174
def enumerated(exceptions, index_offset) exceptions.each_with_index.map do |exception, index| index += index_offset = "#{yield exception}\n#{format_backtrace(exception.backtrace).first}" "#{index_label index}#{indented , index}" end end
#enumerated_errors (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 204
def enumerated_errors enumerated(other_errors, failures.size) do |error| "#{error.class}: #{error.}" end end
#enumerated_failures (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 200
def enumerated_failures enumerated(failures, 0, &: ) end
#exception_count_description
return [String] A description of the failure/error counts.
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 151
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
#exclusion_patterns (private)
[ GitHub ]
#failures ⇒ Array
<RSpec::Expectations::ExpectationNotMetError>
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 122
def failures @failure_aggregator.failures end
#format_backtrace(backtrace) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 188
def format_backtrace(backtrace) backtrace.map { |l| backtrace_line(l) }.compact.tap { |filtered| filtered.concat backtrace if filtered.empty? } end
#indentation (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 219
def indentation @indentation ||= ' ' * longest_index_label_width end
#indented(failure_message, index) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 210
def indented(, index) line_1, *rest = .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) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 231
def index_label(index) " #{index + 1}) " end
#longest_index_label_width (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 223
def longest_index_label_width @longest_index_label_width ||= width_of_label(failures.size) end
#message ⇒ String
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 117
def @message ||= (["#{summary}:"] + enumerated_failures + enumerated_errors).join("\n\n") end
#other_errors ⇒ Array
<Exception
>
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 127
def other_errors @failure_aggregator.other_errors end
#pluralize(noun, count) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 170
def pluralize(noun, count) "#{count} #{noun}#{'s' unless count == 1}" end
#summary ⇒ String
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 145
def summary "Got #{exception_count_description} from failure aggregation " \ "block#{block_description}" end
#width_of_label(index) (private)
[ GitHub ]# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 227
def width_of_label(index) index_label(index).chars.count end