-
-
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
Feature/honest mocks #75
Conversation
I also like the idea of using |
@eproxus so I will make mocks "honest" by default, and introduce an option to allow mocking of non-existing functions/modules. Though I find "unknown" a little bit confusing. What about "non_strict"? |
|
true -> | ||
ok; | ||
_ -> | ||
{error, {cannot_mock_fake, {M, F, A}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find cannot_mock_fake
a bit vague. Cannot come up with anything better, ideas I had were only_existing_functions_allowed
, strict_mode
, function_not_in_original
or only_original_functions
. They're all a bit long though. Perhaps undefined_function
to go with undefined_module
?
Yep, |
@eproxus I made mocks honest by default and changed the exception for the undefined function case as we discussed. |
@eproxus have you had a chance to take a look at the changes? |
@eproxus hey man, how are you? I hope you did not fall off the planet :-) |
@horkhe Haha, no. I just moved to Germany so I've been a bit busy. :-) I'll do a last sweep and then we'll merge. |
init([Mod, Options, Exports]) | ||
catch | ||
error:undef -> | ||
{stop, module_undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To better match undefined_function
, make this undefined_module
instead.
- surround '=' with spaces; - stay within 80 characters.
@eproxus Moved to Germany, that is cool. I suppose that was caused by a generous job offer, so my congratulations! Back to business. The code is rebased and adjusted. |
@horkhe You, sir, are correct. :-) |
By default, only allow mocking of existing modules and functions
@eproxus I am genuinely curious if you new job is Erlang related? |
Yes, it is. I've started working at Wooga in Berlin. If you want a referral, let me know. :-) |
Thanks a lot for the suggestion! :-) |
Meck is so powerful that it allows mocking non-existent functions and even non-existent modules. But as every coin it comes with two sides. And the bad thing here is that all sorts of problem caused by refactoring/removing/renaming actions are not detected by meck featured unit tests. Namely:
To have such cases detected at the earliest possibility honest mocks were introduced. They expose the following properties:
meck:new(mod, [honest])
for a module that does not exist fails withundefined_module
error;cannot_mock_fake
error.I personally think that all mocks created by meck should be honest by default, but I did not want to break the backwards compatibility.