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

Extend protect/2 to accept a list of behviour modules #93

Merged
merged 2 commits into from
Jun 4, 2022

Conversation

camilleryr
Copy link
Contributor

My team loves Hammox since it was recommended to us by Jose - and we really
appreciate all of the work you have put into it!

We often write modules that implement multiple behaviours and have gotten into
the habit of doing something similar to this in many of our tests

  setup_all do
    Map.merge(
      Hammox.protect(My.Module, My.Module.Contract),
      Hammox.protect(My.Module, My.Module.OtherContract)
    )
  end

This PR extends the api to Hammox.protect to be able to take in an
implementation module and a list of behaviours so that we could replace the
above with

  setup_all do
    Hammox.protect(My.Module, [My.Module.Contract, My.Module.OtherContract]),
  end

Please let me know if you have ideas of alternative implementations for this,
or if this does not fit with your design, feel free to disregard!

Once again - thanks for all of your work on this library - it has been very
valuable to our application!

@msz
Copy link
Owner

msz commented Nov 30, 2021

Sorry, I missed this!

I think that's a great idea. Mox also supports defining mocks for multiple behaviours so it only makes sense to mirror that API.

I'll look at the PR in more detail later!

In the meantime, have you considered using Hammox.Protect? It might make your use case just a bit neater:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract
use Hammox.Protect, module: My.Module, behaviour: My.Module.OtherContract

In fact, as we do your proposed change, we could also do it for Hammox.Protect like this:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract, behaviour: My.Module.OtherContract

@camilleryr
Copy link
Contributor Author

Sorry, I missed this!

I think that's a great idea. Mox also supports defining mocks for multiple behaviours so it only makes sense to mirror that API.

I'll look at the PR in more detail later!

In the meantime, have you considered using Hammox.Protect? It might make your use case just a bit neater:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract
use Hammox.Protect, module: My.Module, behaviour: My.Module.OtherContract

In fact, as we do your proposed change, we could also do it for Hammox.Protect like this:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract, behaviour: My.Module.OtherContract

Thanks! I love that suggestion, I added another commit to this PR that allows for the usage of multiple behaviours in use Hammox.Protect as well (the options normalization is a bit hinkey, let me know if you have any thoughts!)

@msz
Copy link
Owner

msz commented Jun 4, 2022

Thank you, and sorry for taking so long to get back to you!

@msz msz merged commit 51be5af into msz:master Jun 4, 2022
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.

2 participants