Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to meck?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bohuslav Svancara  
View profile  
 More options Jan 10 2012, 10:47 am
From: Bohuslav Svancara <bsvanc...@gmail.com>
Date: Tue, 10 Jan 2012 16:47:31 +0100
Local: Tues, Jan 10 2012 10:47 am
Subject: [erlang-questions] How to meck?

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-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Magnus Klaar  
View profile  
 More options Jan 10 2012, 11:50 am
From: Magnus Klaar <magnus.kl...@gmail.com>
Date: Tue, 10 Jan 2012 17:50:06 +0100
Local: Tues, Jan 10 2012 11:50 am
Subject: Re: [erlang-questions] How to meck?

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 <bsvanc...@gmail.com>wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bohuslav Svancara  
View profile  
 More options Jan 10 2012, 6:27 pm
From: Bohuslav Svancara <bsvanc...@gmail.com>
Date: Wed, 11 Jan 2012 00:27:35 +0100
Local: Tues, Jan 10 2012 6:27 pm
Subject: Re: [erlang-questions] How to meck?

Thank you, but it does not help.

---------- modified tested module:
-module(meck_module_for_test).
-compile(export_all).
a() -> a.
call_a() -> *meck_module_for_test:a().* % changed line

-------  testing module "meck_test" is the same (se below)

Result:

1> meck_test:test().
Result of call_a: #Fun<meck_test.1.84433456>
Result of a: #Fun<meck_test.1.84433456>
Valid: true
ok

Bob

2012/1/10 Magnus Klaar <magnus.kl...@gmail.com>

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Magnus Klaar  
View profile  
 More options Jan 10 2012, 7:06 pm
From: Magnus Klaar <magnus.kl...@gmail.com>
Date: Wed, 11 Jan 2012 01:06:23 +0100
Local: Tues, Jan 10 2012 7:06 pm
Subject: Re: [erlang-questions] How to meck?

Hi!

Comparing the output in the two posts, the first one returns 'a' from
call_a() and the return value you specified using meck:expect/4 from the
a() function, the second one shows that both call_a() and a() returns the
value you specified.

If you want to return  "result_from_mocked_a" from these functions you must
invoke meck:expect/3 or /4 as:

meck:expect(meck_module_for_test, a, 0, "result_from_mocked_a") or
meck:expect(meck_module_for_test, a, fun() -> "result_from_mocked_a" end )

MVH Magnus

On Wed, Jan 11, 2012 at 12:27 AM, Bohuslav Svancara <bsvanc...@gmail.com>wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bohuslav Svancara  
View profile  
 More options Jan 11 2012, 5:24 am
From: Bohuslav Svancara <bsvanc...@gmail.com>
Date: Wed, 11 Jan 2012 11:24:53 +0100
Local: Wed, Jan 11 2012 5:24 am
Subject: Re: [erlang-questions] How to meck?

Thanks for your help, Magnus. It works fine now.

Bob

2012/1/11 Magnus Klaar <magnus.kl...@gmail.com>

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »