Class: RSpec::Matchers::BuiltIn::Compound::NestedEvaluator Private
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::Compound::NestedEvaluator
- Defined in:
- lib/rspec/matchers/built_in/compound.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Normally, we evaluate the matching sequentially. For an expression like
expect(x).to foo.and bar
, this becomes:
expect(x).to foo expect(x).to bar
For block expectations, we need to nest them instead, so that
expect { x }.to foo.and bar
becomes:
expect { expect { x }.to foo }.to bar
This is necessary so that the expect
block is only executed once.
Instance Method Summary (collapse)
-
- (NestedEvaluator) initialize(actual, matcher_1, matcher_2)
constructor
private
A new instance of NestedEvaluator.
- - (Boolean) matcher_matches?(matcher) private
Constructor Details
- (NestedEvaluator) initialize(actual, matcher_1, matcher_2)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of NestedEvaluator
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rspec/matchers/built_in/compound.rb', line 130 def initialize(actual, matcher_1, matcher_2) @actual = actual @matcher_1 = matcher_1 @matcher_2 = matcher_2 @match_results = {} inner, outer = order_block_matchers @match_results[outer] = outer.matches?(Proc.new do |*args| @match_results[inner] = inner.matches?(inner_matcher_block(args)) end) end |
Instance Method Details
- (Boolean) matcher_matches?(matcher)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 |
# File 'lib/rspec/matchers/built_in/compound.rb', line 143 def matcher_matches?(matcher) @match_results.fetch(matcher) end |