Skip to content

Commit

Permalink
[expectations] Fix support for dynamic matchers
Browse files Browse the repository at this point in the history
See rspec/rspec-collection_matchers#48

If a matcher supports dynamic arbitrary methods called on it, e.g.
`have_at_least(100).bucks`, it would also consider a
`supports_value_expectations?` call as a dynamic part.

Instead of calling `supports_*?` methods on a matcher, explicitly
check if it responds to it.

---
This commit was imported from rspec/rspec-expectations@d8f272a.
  • Loading branch information
pirj committed Mar 5, 2021
1 parent e896fda commit 3988e9f
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ def enforce_value_expectation(matcher)
end

def supports_value_expectations?(matcher)
matcher.supports_value_expectations?
rescue NoMethodError
true
!matcher.respond_to?(:supports_value_expectations?) || matcher.supports_value_expectations?
end
end

Expand Down Expand Up @@ -155,9 +153,7 @@ def enforce_block_expectation(matcher)
end

def supports_block_expectations?(matcher)
matcher.supports_block_expectations?
rescue NoMethodError
false
matcher.respond_to?(:supports_block_expectations?) && matcher.supports_block_expectations?
end
end
end
Expand Down

0 comments on commit 3988e9f

Please sign in to comment.