123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Expectations::FailureAggregator Private

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: rspec-expectations/lib/rspec/expectations/failure_aggregator.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#block_label (readonly)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 5

attr_reader :block_label, :

#metadata (readonly)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 5

attr_reader :block_label, :

Instance Method Details

#aggregate

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 27

def aggregate
  RSpec::Support.with_failure_notifier(self) do
    begin
      yield
    rescue ExpectationNotMetError => e
      # Normally, expectation failures will be notified via the `call` method, below,
      # but since the failure notifier uses a thread local variable, failing expectations
      # in another thread will still raise. We handle that here and categorize it as part
      # of `failures` rather than letting it fall through and be categorized as part of
      # `other_errors`.
      failures << e
    rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
      # While it is normally a bad practice to rescue `Exception`, it's important we do
      # so here. It's low risk (`notify_aggregated_failures` below will re-raise the exception,
      # or raise a `MultipleExpectationsNotMetError` that includes the exception), and it's
      # essential that the user is notified of expectation failures that may have already
      # occurred in the `aggregate_failures` block. Those expectation failures may provide
      # important diagnostics for understanding why this exception occurred, and if we simply
      # allowed this exception to be raised as-is, it would (wrongly) suggest to the user
      # that the expectation passed when it did not, which would be quite confusing.
      other_errors << e
    end
  end

  notify_aggregated_failures
end

#assign_backtrace(failure) (private)

On JRuby 9.1.x.x and before, caller and raise produce different backtraces with regards to .java stack frames. It’s important that we use raise for JRuby to produce a backtrace that has a continuous common section with the raised MultipleExpectationsNotMetError, so that rspec-core’s truncation logic can work properly on it to list the backtrace relative to the aggregate_failures block. :nocov:

See additional method definition at line 84.

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 92

def assign_backtrace(failure)
  raise failure
rescue failure.class => e
  failure.set_backtrace(e.backtrace)
end

#call(failure, options)

This method is defined to satisfy the callable interface expected by Support.with_failure_notifier.

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 64

def call(failure, options)
  source_id = options[:source_id]
  return if source_id && @seen_source_ids.key?(source_id)

  @seen_source_ids[source_id] = true
  assign_backtrace(failure) unless failure.backtrace
  failures << failure

  AGGREGATED_FAILURE
end

#failures

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 54

def failures
  @failures ||= []
end

#notify_aggregated_failures (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 103

def notify_aggregated_failures
  all_errors = failures + other_errors

  case all_errors.size
  when 0 then return true
  when 1 then RSpec::Support.notify_failure all_errors.first
  else RSpec::Support.notify_failure MultipleExpectationsNotMetError.new(self)
  end
end

#other_errors

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/expectations/failure_aggregator.rb', line 58

def other_errors
  @other_errors ||= []
end