Skip to content
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

Add support for custom matcher functions #147

Merged
merged 1 commit into from
Oct 19, 2019

Conversation

Geekfish
Copy link
Contributor

@Geekfish Geekfish commented Sep 13, 2019

Hello!

This changeset adds the ability to specify any function (or set of functions)
that provide custom matching behaviour by using a new custom_matchers option.

As demonstrated in the example provided in the README.md and tests, this should allow to resolve issues like #134 where more specific matching logic is for whatever reason required.

This also opens the possibility of a bigger refactor, where even the "default" matchers (url, method, headers, body etc) are simply functions that are applied in the same way, and users can decide which ones to use or not (removing the need for the match_requests_on option).

This changeset adds the ability to specify any function (or set of functions)
that provide custom matching behaviour by using a new `custom_matchers` option.
defp always_map(headers) do
# When a request is first recorded then the request headers are stored
# as a List, but when it's fetched from storage then they are a Map...
if(is_list(headers), do: Enum.into(headers, %{}), else: headers)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I missed something with this, but maybe on a different issue we can make this consistent (either a List or a Map).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 92.986% when pulling 2a076ff on Geekfish:enhance/custom-matchers into ebb0b5a on parroty:master.

@parroty parroty merged commit c64dab6 into parroty:master Oct 19, 2019
@parroty
Copy link
Owner

parroty commented Oct 19, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants