-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create nested-equals matcher #218
Conversation
This solves a common need of matching nested maps with strict equality. | ||
See also: `match-with`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to suggest a better explanation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something more like the following which explains it in broader terms and mentions the fact that there are defaults that are being overridden:
A matcher that always uses the
equals
matcher at every level of nesting. Useful given that matchers usually only change the first level of the data they are applied to, leaving nested data to use the default matcher of that type of data. For instance, this can be used to assert that any nested map has exactly the same keys and matching values as provided in theexpected
, and no more.Note: this excludes functions, which continue to be invoked as predicates instead of compared via the
equals
matcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added regex
exclusion too. Feel free to correct me if I'm wrong
other possible names for
As a note, the midje implementation had a similar thing, |
I think we should have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for the PR!
Can you add the matcher to the list in the readme?: https://github.com/nubank/matcher-combinators#built-in-matchers
Also the https://github.com/nubank/matcher-combinators#overriding-default-matchers mentions a match-with
example that could be replaced with strictly-equals
. Could you add a line there that says "For convenience we've also added this as a built-in matcher called strictly-equals
?
This solves a common need of matching nested maps with strict equality. | ||
See also: `match-with`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something more like the following which explains it in broader terms and mentions the fact that there are defaults that are being overridden:
A matcher that always uses the
equals
matcher at every level of nesting. Useful given that matchers usually only change the first level of the data they are applied to, leaving nested data to use the default matcher of that type of data. For instance, this can be used to assert that any nested map has exactly the same keys and matching values as provided in theexpected
, and no more.Note: this excludes functions, which continue to be invoked as predicates instead of compared via the
equals
matcher
@philomates I have replaced the |
I have also added the versions changes to be validated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I'll defer to @philomates's review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Was mulling the name over a little bit more and nested-equals
came up. I like it because it refers to nesting, which is really where this differs from the default. Like the matcher used for functions and regex stays the same, but for any nested/container datastructure equals is used instead of whatever default.
What do you think? Or should we just stick with this?
Create
nested-equals
function to match nested maps withequals
and providing a documentation closer to the code about the nested behavior for matchers.Closes #217