Skip to content

Commit

Permalink
Merge pull request #104 from horkhe/feature/implicit-new
Browse files Browse the repository at this point in the history
Implement 'implicit new' feature #80
  • Loading branch information
eproxus committed Apr 24, 2013
2 parents 06a3029 + 767f238 commit 334e89d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/meck_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,23 @@ get_result_spec(Mod, Func, Args) ->
gen_server(call, Mod, {get_result_spec, Func, Args}).

-spec set_expect(Mod::atom(), meck_expect:expect()) ->
ok | {error, Reason :: any()}.
ok | {error, Reason::any()}.
set_expect(Mod, Expect) ->
gen_server(call, Mod, {set_expect, Expect}).
Proc = meck_util:proc_name(Mod),
try
gen_server:call(Proc, {set_expect, Expect})
catch
exit:{noproc, _Details} ->
Props = [Mod, [passthrow]],
case gen_server:start({local, Proc}, ?MODULE, Props, []) of
{ok, Pid} ->
Result = gen_server:call(Proc, {set_expect, Expect}),
true = erlang:link(Pid),
Result;
{error, {{undefined_module, Mod}, _StackTrace}} ->
erlang:error({not_mocked, Mod})
end
end.

-spec delete_expect(Mod::atom(), Func::atom(), Ari::byte()) -> ok.
delete_expect(Mod, Func, Ari) ->
Expand Down
6 changes: 6 additions & 0 deletions test/meck_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ meck_module_attributes_test() ->
meck_test_module:module_info()))),
?assertEqual(ok, meck:unload(meck_test_module)).

meck_implicit_new_test()->
meck:expect(meck_test_module, c, [{[1, 1], foo},
{['_', '_'], bar}]),
?assertMatch(foo, meck_test_module:c(1, 1)),
meck:unload().

%%=============================================================================
%% Internal Functions
%%=============================================================================
Expand Down

0 comments on commit 334e89d

Please sign in to comment.