-
-
Notifications
You must be signed in to change notification settings - Fork 231
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 meck:get_state/0, meck:reset_state/0 #125
Comments
With state of the mocks, do you only mean the validation state ( |
No, I mean the entire state. I'd like (if possible) to pickle and unpickle the entire state of all extant mocks -- stubs, mocks and fakes. Not necessarily expectations. Let me take a step back here. The core problem is that However, the only way for There is But that removes any I guess, instead of saving/restoring state, Then I could have: fixture_setup() ->
meck:new(Mods).
fixture_cleanup() ->
meck:unload().
case_setup() ->
meck:stub_all(ModsToStub),
meck:passthrough(ModsToPassThrough),
meck:expect(OtherStuff).
case_cleanup() ->
meck:reset(),
meck:delete(). |
Oh, and the problem I found when attempting to write |
Ok, I see what you mean, I think. When creating a mock, a new module is compiled (and the state is saved in the Meck process). When adding functions, passthroughs etc. the whole module is recompiled (since there is no way to add functions to an existing module in Erlang). This leads to that every I suspect what you proposed would be equally slow to calling new, because everything will result in one or several recompilations anyway ( |
Closing and documenting in the wiki instead: https://github.com/eproxus/meck/wiki#feature-ideas Please comment here if you have information or requests to add, and/or want to discuss a PR or possible implementation proposal. |
I have an alternative, related, suggestion: We have a lot of fixture setup of the form:
This requires recompiling the module on each |
Yeah, this is something I thought about as well, to have mock templates that compile everything in one go. Good point. It's not possible at the moment, only different clauses for the same function at the same time. It's something I want to do for 2.0-something, to make the expects API more coherent and simpler (basically a tree structure of mod/func/clause, which would also make templating easier. |
meck:new and meck:unload are quite slow. I attempted to use fixture setup and cleanup in eunit to only call them once for the fixture:
But then I have difficulty deleting expectations in case_cleanup: if I implement meck:delete/0, then it also removes expectations that were set up in fixture_setup and case_setup.
In particular
passthrough
andstub_all
expectations.So, I figure it'd be nice to be able to return an opaque term representing the current expectations at the end of case_setup. EUnit conveniently passes this to case_cleanup, where it could be restored with meck:reset_state/0.
This would save the slow meck:new and meck:unload on each case, but would guarantee that the state of the mocks was restored for the next test.
The text was updated successfully, but these errors were encountered: