-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require exact match for top-level Hash parameter
In this commit [1] which fixed #647 and which was released in v2.3.0, a top-level `Hash` argument passed into `Expectation#with` was implicitly converted into a `HasEntries` matcher in order to handle "nested" matchers used within the keys & values of the `Hash`. This _new_ behaviour makes particular sense for keyword arguments where the requirement to wrap such a `Hash` in a call to `#has_entries` was a bit surprising as described in #647. However, that change inadvertently broke basic `Hash` parameter matching as described in #657, because the `HasEntries` matcher only needs to match each of the entries specified; it will still match if there are *extra* entries in the `Hash` it is matching against. In order to fix this without breaking the "nested" matching behaviour added in [1], I've added an optional `exact` keyword argument to the `HasEntries` constructor and set this to `true` when it's called from `PositionalOrKeywordHash#matches?`. I haven't bothered to document the new `exact` argument, because currently it's only used internally. I did consider introducing a new matcher more like `RSpec::Matchers#match` matcher [2], but I decided that wouldn't provide as elegant a solution to #647 as the change in this commit. I can imagine introducing something like `#has_exact_entries` to the public API, but it would probably make sense to add something similar for exact matching of array items at the same time, so I'm going to leave that for now. I've added a few acceptance tests in this commit which would have caught the problem that I inadvertently introduced in [1] and a few that cover the "nested" matching behaviour that was introduced in that commit (previously I had only added a unit test). [1]: f94e250 [2]: https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers#match-instance_method
- Loading branch information
1 parent
18448d1
commit 5e6a07b
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters