Skip to content

No way to match on a subset of meta #10

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

Closed
mykecameron opened this issue Jul 19, 2018 · 6 comments
Closed

No way to match on a subset of meta #10

mykecameron opened this issue Jul 19, 2018 · 6 comments

Comments

@mykecameron
Copy link

have_meta will only succeed on EXACT matches. Often I have shared examples that test for some omnipresent meta in responses across many endpoints (example, a UUID identifying the request which we use for debugging), but then some meta contents which are specific to a particular resource or API (example: pagination data for an index endpoint).

We added a contain_meta matcher for this in our applications, happy to share back w/ a PR.

Check out: master...mykecameron:add_partial_meta_matcher, I didn't want to open an unsolicited PR since its unclear to me what the best practices around contribution to this project are, or even if it is actively maintained. Any guidance would be appreciated!

@stas
Copy link
Collaborator

stas commented Jan 17, 2020

@mykecameron, apologies for the late reply.

I think it's better to make have_meta work as contain rather than equal. I don't think we should introduce a new matcher just for this. Alternatively, let's add an option for the matcher to chain on exactly this behavior.

I'll be happy to take a look if you send a PR.
Thanks 🙇‍♂️

@stas
Copy link
Collaborator

stas commented Feb 15, 2020

Related #14 if somebody wants to pick it up 😃

@sa73917
Copy link
Contributor

sa73917 commented Jul 8, 2020

@stas - something like this? will make have_meta work as a contain rather than an equal with the exactly chain. Though this does risk breaking people's existing tests who are expecting have_meta to be an exact match.

@stas
Copy link
Collaborator

stas commented Jul 9, 2020

@sa73917 yup, though the way you're checking for the subset could be a bit optimized, take a look at these sugestions (probably worth looking at the ruby v2.4+ compatibility though, so <= operator should be more than enough).

Thanks!

@sa73917
Copy link
Contributor

sa73917 commented Jul 10, 2020

Changed the subset logic as suggested and raised a PR

@stas
Copy link
Collaborator

stas commented Jul 12, 2020

Fixed in #22 thanks to @sa73917!

@stas stas closed this as completed Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants