Skip to content

Commit

Permalink
fixup! Cache predicate results
Browse files Browse the repository at this point in the history
To avoid predicate from being called multiple times.
This causes rspec-mocks failure:

    1) Using a partial mock on a proxy object works properly
       Failure/Error: expect(proxy).to receive(:proxied?).and_return(false)

         (#<Object:0x00007fa5f658ad10>).proxied?(*(any args))
             expected: 1 time with any arguments
             received: 3 times with any arguments
       # ./spec/rspec/mocks/partial_double_spec.rb:237:in `block (2 levels) in <module:Mocks
  • Loading branch information
pirj committed Jul 18, 2021
1 parent f511409 commit bf684ea
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rspec/matchers/built_in/has.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ def predicate_matches?(value=true)
if RSpec::Expectations.configuration.strict_predicate_matchers?
value == predicate_result
else
if value == !!predicate_result && value != predicate_result
predicate_actual = predicate_result
if value == !!predicate_actual && value != predicate_actual
RSpec.deprecate(
"`#{predicate_method_name}` returned neither `true` nor `false`, but rather `#{predicate_result.inspect}`")
"`#{predicate_method_name}` returned neither `true` nor `false`, but rather `#{predicate_actual.inspect}`")
end
value == !!predicate_result
value == !!predicate_actual
end
end

Expand Down

0 comments on commit bf684ea

Please sign in to comment.