[erlang-questions] How to meck?

Magnus Klaar magnus.klaar@REDACTED
Tue Jan 10 17:50:06 CET 2012


Hi!

You can only mock external calls using meck, this means that you must
prefix the call to a() in meck_module_for_test:call_a/0 with
 meck_module_for_test: or ?MODULE: to ensure that the call is handled by
the mocked version of the module. When you make a local call to a function
in the same module it will always call the function defined in the current
module version.

MVH Magnus

On Tue, Jan 10, 2012 at 4:47 PM, Bohuslav Svancara <bsvancara@REDACTED>wrote:

> Hello!
> I am trying to use meck, but have no luck.
> Can you help me, please?
>
> Erlang version: Erlang 5.9/OTP R15B
>
> ---------- tested module:
> -module(meck_module_for_test).
> -compile(export_all).
> a() -> a.
> call_a() -> a().
>
> ------------------------- testing module:
> -module(meck_test).
> -compile(export_all).
> test()->
>     ok = meck:new(meck_module_for_test,[passthrough]), % Docs says:
> Retains the original functions, if not mocked by meck.
>
>     % Mock "a()" which is called from call_a().
>     ok = meck:expect(meck_module_for_test, a, 0, fun() ->
> "result_from_mocked_a" end ),
>
>     Result = meck_module_for_test:call_a(),
>     io:format("Result of call_a: ~p~n",[Result]),
>
>     Result_A = meck_module_for_test:a(),
>     io:format("Result of a: ~p~n",[Result_A]),
>
>     Valid = meck:validate(meck_module_for_test),
>     io:format("Valid: ~p~n",[Valid]),
>
>     meck:unload(meck_module_for_test),
>     ok.
>
> --------------------- result of meck_test:test():
> Result of call_a: a
> Result of a: #Fun<meck_test.1.126597877>
> Valid: true
> ok
> -----------------------------
>
> I believe that call_a() should call a mocked version of a() which should
> return "result_from_mocked_a".
> So the result from call_a() shoud be:"result_from_mocked_a"
> But my results are different.
>
> Can you help me, please?
>
> Thanks,
> Bob
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120110/7cc2f4a1/attachment.htm>


More information about the erlang-questions mailing list