Comments (6)
According to the validate
edoc "The function returns true
if the mocked module(s) has been used according to its expectations. It returns false
if a call has failed in some way. Reasons for failure are wrong number of arguments or non-existing function (undef), wrong arguments (function clause) or unexpected exceptions." It does not check that everything that you set expectations for is called, it just make sure that nothing crashed during your test so to speak.
I would recommend you to use meck
in record-verify manner, that is to treat expectations as stubs that are defined in you test Given section and verify that post-conditions are met with num_calls/3
function in the test Then section.
from meck.
OK. I get it. But I think the names and the documentation is confusing. When I use meck:expect I expect something and I also expect meck:validate to validate that the mocked module(s) has been used according to my expectations. But obviously the expectations of meck and my expectations are different, then why is meck:expect called "expect" why not "stub" or "when"?
Still, thank you for the quick response and clarifications.
from meck.
I started contributing to this project just recently, and I do not know the original author's intention. It is hard to guess since on the one hand the name of the main function is expect
that tells that it is an expectation framework, but on the other hand expect
does not allow expecting a particular number of invocations and verification functions (called
and num_calls
) are provided that are typical for record-verify frameworks.
My personal desire is to move Meck API and feature set more towards the record-verify model of use (like Mockito in Java). And all I do is driven by this purpose. But that is just my opinion and Adam (@eproxus) - the project author - might not side with me. But if majority of Meck user base supports this motion then it will probably happen, and expect
will be substituted with stub
or at least stub
synonym will be provided.
I am going to write a Wiki page that explains how to use Meck in record-verify style but for that I need a couple of more features to make it at least in to the develop branch.
from meck.
Well, breaking the API just to fix a couple of bad names sounds like too much to me. Mockito is a pretty good framework but currently using meck one can do almost everything that can be done using Mockito. What I want to see is more erlang specific features not just a clone of Mochito. I would like to see more features that allow to mock interaction between processes more easily. For example:
Pid = meck:new_proc(),
... do something with Pid
meck:received(Pid, Message_pattern) %true if Pid received a message that matches the Message_pattern
from meck.
The name expect
was just picked in the beginning as something of a "expect this result when the function is called", not "expect this function to be called". I agree that the naming is not the best, and am open for suggestions on better names that can be added as alias functions provided they provide a bigger improvement.
I've often though about added helpers for processes, but the conclusion has always been that Meck wouldn't be able to provide some significant improvement over Erlang itself in this regard. Consider:
Pid = self(),
... do something with Pid
receive Message_pattern -> true; _ -> false end %true if Pid received a message that matches the Message_pattern
The gain is not so big. If some more structure is needed one can easily add a small helper function in ones tests. Generalizing this one often just ends up with abstractions over Erlang's own pattern (!
, recieve
etc.).
That said, I'm happy to get any suggestions on how this could be done, of course.
from meck.
While helpers for this simple case would be an unnecessary abstraction, some helpers could be useful, eg when
waiting for a sequence of messages.
I strongly believe that it is more useful to express that kind of logic as a state machine though. Something like quickchecks state machines/trace verification mechanism. Will do some more thinking :)
from meck.
Related Issues (20)
- History item is not kept while module compiler is running HOT 3
- Remove compatibility for Erlang R15 and R16
- Is there a convenient way to repalce a moudle by a stub moudle, which not need to expect each function ? HOT 2
- Crash when mocking Elixir 1.8-rc.0 compiled module HOT 1
- Issues with interaction of meck with cover + eunit HOT 5
- Module references in typespecs are not included when renaming modules HOT 2
- Warnings in cover server when mecking distributed nodes with rebar3 do eunit,ct HOT 2
- meck:ret_spec() opaqueness violates documented usage patterns HOT 4
- Can not unload after passthrough meck HOT 3
- merge_expects together with passthrough seems does not set up the mocking HOT 2
- Getting meck_proc already started errors HOT 7
- References to hamcrest yield dialyzer warnings HOT 2
- Release request HOT 3
- One of the example shown on README page doesn't work HOT 2
- Update GitHub Actions to use setup-beam HOT 2
- Create proper issue templates
- Compilation results in files under deps/meck being updated HOT 3
- How to install on windows(win10) HOT 1
- How to install meck on windows HOT 2
- Deleting existing function does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meck.