[erlang-questions] Mocking I/O calls - defining sequence of returns
Gustav Simonsson
gustav.simonsson@REDACTED
Mon May 23 12:45:14 CEST 2011
If using meck, you can solve that problem a few different ways depending on the context:
if you have control between the different calls (in a test-scenario of a FSM for example) to
your mocked function, you can simply define a new mocking behaviour for that function between the calls
(with meck:passthrough/1 if you want the original function to be called).
In the case where you do not have that control, you have to write the mocked fun() sent to meck:expect/3/4 to return different values for different arguments.
In a scenario where you do not have control between the calls, and you send exactly the same arguments to the function several times but want it to behave differently, you can make use of meck:history/1 as in the examples Tim Watson presented earlier in this thread.
Regards,
Gustav Simonsson
----- Original Message -----
From: "Alyssa Kwan" <alyssa.c.kwan@REDACTED>
To: "Edward Wang" <edward.yujiang.wang@REDACTED>
Cc: erlang-questions@REDACTED
Sent: Saturday, May 21, 2011 8:40:30 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [erlang-questions] Mocking I/O calls - defining sequence of returns
I'm sorry, I wasn't being specific. Is there any way to mock a sequence of calls to the same function? Like if I call io:get_line (or a wrapper because it's protected), how do I get it to return a different value for the first call and the second call?
Also, will it expect exactly two calls as well? And does meck record call order for different functions?
On May 21, 2011, at 1:43 PM, Edward Wang wrote:
Try meck https://github.com/eproxus/meck
I used it to mock inet:getifaddrs/0 etc.
On Sun, May 22, 2011 at 1:31 AM, Alyssa Kwan < alyssa.c.kwan@REDACTED > wrote:
Hi everyone!
Are there any mocking libraries written that allow you to expect a sequence of calls and return a different value for each call? A mocking library that allows passthrough would be ideal.
Thanks!
Alyssa
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list