Hi!<div><br></div><div>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.</div>
<div><br></div><div>MVH Magnus<br><br><div class="gmail_quote">On Tue, Jan 10, 2012 at 4:47 PM, Bohuslav Svancara <span dir="ltr"><<a href="mailto:bsvancara@gmail.com">bsvancara@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello!<br>I am trying to use meck, but have no luck.<br>Can you help me, please?<br><br>Erlang version: Erlang 5.9/OTP R15B <br>
<br>---------- tested module:<br>-module(meck_module_for_test).<br>-compile(export_all).<br>a() -> a.<br>call_a() -> a().<br><br>------------------------- testing module:<br>-module(meck_test).<br>-compile(export_all).<br>


test()-><br>    ok = meck:new(meck_module_for_test,[passthrough]), % Docs says: Retains the original functions, if not mocked by meck. <br>    <br>    % Mock "a()" which is called from call_a().<br>    ok = meck:expect(meck_module_for_test, a, 0, fun() -> "result_from_mocked_a" end ),<br>


    <br>    Result = meck_module_for_test:call_a(),<br>    io:format("Result of call_a: ~p~n",[Result]),<br>    <br>    Result_A = meck_module_for_test:a(),<br>    io:format("Result of a: ~p~n",[Result_A]),<br>


    <br>    Valid = meck:validate(meck_module_for_test),<br>    io:format("Valid: ~p~n",[Valid]),<br>    <br>    meck:unload(meck_module_for_test),    <br>    ok.<br><br>--------------------- result of meck_test:test():<br>


Result of call_a: a<br>Result of a: #Fun<meck_test.1.126597877><br>Valid: true<br>ok<br>-----------------------------<br><br>I believe that call_a() should call a mocked version of a() which should return "result_from_mocked_a".<br>


So the result from call_a() shoud be:"result_from_mocked_a"<br>But my results are different.<br><br>Can you help me, please?<br><br>Thanks,<br>Bob<br>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>