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 a further caveat to using meck with ct #225

Merged
merged 1 commit into from
Mar 5, 2021
Merged

Add a further caveat to using meck with ct #225

merged 1 commit into from
Mar 5, 2021

Conversation

paulo-ferraz-oliveira
Copy link
Contributor

As discussed over Slack, we should probably add this caveat to the README.

@eproxus
Copy link
Owner

eproxus commented Mar 3, 2021

May I suggest this text instead?

### Common Test

When using `meck` under Erlang/OTP's Common Test, one should pay special
attention to this bit in the chapter on
[Writing Tests](https://erlang.org/doc/apps/common_test/write_test_chapter.html):
 
> `init_per_suite` and `end_per_suite` execute on dedicated Erlang processes,
> just like the test cases do.

Common Test runs `init_per_suite` in an isolated process which terminates when
done, before the test case runs. A mock that is created there will also
terminate and unload itself before the test case runs. This is because it is
linked to the process creating it. This can be especially tricky to detect if
`passthrough` is used when creating the mock, since it is hard to know if it is
the mock responding to function calls or the original module.

To avoid this, you can pass the `no_link` flag to `meck:new/2` which will unlink
the mock from the process that created it. When using `no_link` you should make
sure that `meck:unload/1` is called properly (for all test outcomes, or
crashes) so that a left-over mock does not interfere with subsequent test
cases.

@paulo-ferraz-oliveira
Copy link
Contributor Author

Done: 6f45f1a.

@eproxus eproxus merged commit c287994 into eproxus:master Mar 5, 2021
@eproxus
Copy link
Owner

eproxus commented Mar 5, 2021

Will release a new version with this and #223 as soon as I have some spare time.

@paulo-ferraz-oliveira
Copy link
Contributor Author

Sure thing, @eproxus. Thanks again.

@paulo-ferraz-oliveira paulo-ferraz-oliveira deleted the feature/ct_caveat_in_readme branch March 5, 2021 11:13
@eproxus
Copy link
Owner

eproxus commented Mar 6, 2021

0.9.2 is released with this PR included.

@paulo-ferraz-oliveira
Copy link
Contributor Author

Thanks much, Adam.

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