Skip to content

Commit

Permalink
Fix re adding shortcut expects
Browse files Browse the repository at this point in the history
  • Loading branch information
eproxus committed Jun 9, 2011
1 parent 1145f7a commit 9b8934a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/meck.erl
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,7 @@ delete_expect(Mod, Func, Arity, Expects) ->

change_expects(Op, Mod, Func, Value, Expects) ->
NewExpects = Op(Expects, Func, Value),
% only recompile if function was added or arity was changed
case interface_equal(NewExpects, Expects) of
true -> ok;
false -> meck_mod:compile_and_load_forms(to_forms(Mod, NewExpects))
end,
meck_mod:compile_and_load_forms(to_forms(Mod, NewExpects)),
NewExpects.

e_store(Expects, Func, Expect) ->
Expand Down
9 changes: 3 additions & 6 deletions test/meck_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ meck_test_() ->
fun shortcut_expect_negative_arity_/1,
fun shortcut_call_return_value_/1,
fun shortcut_call_argument_/1,
fun shortcut_re_add_/1,
fun delete_/1,
fun called_false_no_args_/1,
fun called_true_no_args_/1,
Expand Down Expand Up @@ -192,12 +193,8 @@ caller_does_not_crash_on_reload_(Mod) ->
change_func_(Mod) ->
ok = meck:expect(Mod, test, fun() -> 1 end),
?assertEqual(1, Mod:test()),
MTime = proplists:get_value(time, Mod:module_info(compile)),
% recompile will result in increased module_info time
timer:sleep(1100),
ok = meck:expect(Mod, test, fun() -> 2 end),
?assertEqual(2, Mod:test()),
?assertEqual(MTime, proplists:get_value(time, Mod:module_info(compile))).
?assertEqual(2, Mod:test()).

call_original_undef_(Mod) ->
ok = meck:expect(Mod, test, fun() -> meck:passthrough([]) end),
Expand Down Expand Up @@ -294,7 +291,7 @@ shortcut_call_argument_(Mod) ->
?assertEqual(apa, Mod:test(hest, 1)),
?assertEqual(true, meck:validate(Mod)).

shortcut_re_add(Mod) ->
shortcut_re_add_(Mod) ->
ok = meck:expect(Mod, test, 2, apa),
?assertEqual(apa, Mod:test(hest, 1)),
ok = meck:expect(Mod, test, 2, new),
Expand Down

0 comments on commit 9b8934a

Please sign in to comment.