Skip to content

Commit

Permalink
Throw error when mocking sticky modules without unstick
Browse files Browse the repository at this point in the history
  • Loading branch information
eproxus committed Jul 13, 2011
1 parent 66bbd7f commit 8810a71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/meck.erl
Expand Up @@ -289,8 +289,14 @@ init([Mod, Options]) ->
Original = backup_original(Mod),
process_flag(trap_exit, true),
Expects = init_expects(Mod, Options),
meck_mod:compile_and_load_forms(to_forms(Mod, Expects)),
{ok, #state{mod = Mod, expects = Expects, original = Original, was_sticky = WasSticky}}.
try
meck_mod:compile_and_load_forms(to_forms(Mod, Expects)),
{ok, #state{mod = Mod, expects = Expects, original = Original,
was_sticky = WasSticky}}
catch
exit:{error_loading_module, Mod, sticky_directory} ->
{stop, module_is_sticky}
end.

%% @hidden
handle_call({get_expect, Func, Arity}, _From, S) ->
Expand Down
3 changes: 3 additions & 0 deletions test/meck_tests.erl
Expand Up @@ -723,6 +723,9 @@ can_mock_sticky_module_not_yet_loaded_({Mod, _}) ->
?assertEqual(ok, meck:unload(Mod)),
?assert(code:is_sticky(Mod)).

cannot_mock_sticky_module_without_unstick_({Mod, _}) ->
?assertError(module_is_sticky, meck:new(Mod, [no_link])).

can_mock_non_sticky_module_test() ->
?assertNot(code:is_sticky(meck_test_module)),
?assertEqual(ok, meck:new(meck_test_module, [unstick])),
Expand Down

0 comments on commit 8810a71

Please sign in to comment.