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 Bamboo.TestAdapter.forward/2 #620

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jonleighton
Copy link

This provides a way to receive emails from other processes without
resorting to shared mode and synchronous tests.

For background, this builds on some work that I did to allow Wallaby
tests to play nicely with Mox, while still allowing the tests to be
async. I wrote about it here:

https://jonleighton.name/2021/asynchronous-browser-tests-with-phoenix/

And then contributed some docs to Wallaby about the setup here:

elixir-wallaby/wallaby#592

This commit basically implements a kind of Mox.allow/3 function for
Bamboo.TestAdapter.

Note that I’ve changed the order of the arguments for this
Bamboo.TestAdapter.forward/2 function. For Mox.allow/3, the owner_pid
comes first:

Mox.allow(MyMock, owner_pid, child_pid)

But for Bamboo.TestAdapter.forward/2, the child_pid comes first:

Bamboo.TestAdapter.forward(child_pid, owner_pid)

My reasoning is that in the first example we’re allowing the child_pid
to access mocks defined by the owner pid. But in the second example,
we’re forwarding emails FROM the child_pid TO the owner_pid. So this
order of arguments seemed to make sense to me, but may be slightly
confusing.

This provides a way to receive emails from other processes without
resorting to shared mode and synchronous tests.

For background, this builds on some work that I did to allow Wallaby
tests to play nicely with Mox, while still allowing the tests to be
async. I wrote about it here:

https://jonleighton.name/2021/asynchronous-browser-tests-with-phoenix/

And then contributed some docs to Wallaby about the setup here:

elixir-wallaby/wallaby#592

This commit basically implements a kind of Mox.allow/3 function for
Bamboo.TestAdapter.

Note that I’ve changed the order of the arguments for this
Bamboo.TestAdapter.forward/2 function. For Mox.allow/3, the owner_pid
comes first:

    Mox.allow(MyMock, owner_pid, child_pid)

But for Bamboo.TestAdapter.forward/2, the child_pid comes first:

    Bamboo.TestAdapter.forward(child_pid, owner_pid)

My reasoning is that in the first example we’re allowing the child_pid
to access mocks defined by the owner pid. But in the second example,
we’re forwarding emails FROM the child_pid TO the owner_pid. So this
order of arguments seemed to make sense to me, but may be slightly
confusing.
@germsvel
Copy link
Collaborator

germsvel commented Aug 9, 2021

Thanks for opening this PR @jonleighton! I really like the idea of what you're doing here. I'll try to find some time later this week to give it a good review.

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.

None yet

2 participants