Skip to content

Instantly share code, notes, and snippets.

@dreid
Created April 11, 2011 18:05
Show Gist options
  • Save dreid/913953 to your computer and use it in GitHub Desktop.
Save dreid/913953 to your computer and use it in GitHub Desktop.
A rather convoluted mechanism for getting subsequent calls to a mecked function to return different results.
-module(multiple_expect_results).
-include_lib("eunit/include/eunit.hrl").
multiple_results_test() ->
ok = meck:new(some_mod),
meck:expect(some_mod, get_pid, fun() -> self() end),
meck:expect(some_mod, some_fun,
fun() ->
receive
{{some_mod, some_fun}, Result} ->
Result
end
end),
ModPid = some_mod:get_pid(),
ModPid ! {{some_mod, some_fun}, a},
ModPid ! {{some_mod, some_fun}, b},
ModPid ! {{some_mod, some_fun}, c},
?assertEqual(a, some_mod:some_fun()),
?assertEqual(b, some_mod:some_fun()),
?assertEqual(c, some_mod:some_fun()).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment