Skip to content
Browse files

Fix {stub_all, undefined} and {stub_all, true} cases

  • Loading branch information...
1 parent bf015c7 commit d690ad45cd844cc1748aa9963b669180bf3406ae Maxim Vladimirsky committed Oct 23, 2012
Showing with 25 additions and 16 deletions.
  1. +8 −6 src/meck.erl
  2. +17 −10 test/meck_tests.erl
View
14 src/meck.erl
@@ -659,18 +659,20 @@ resolve_can_expect(Exports, Options) ->
init_expects(Exports, Options) ->
Passthrough = proplists:get_bool(passthrough, Options),
- StubRet = proplists:get_value(stub_all, Options),
+ StubAll = proplists:is_defined(stub_all, Options),
Expects = case Exports of
undefined ->
[];
Exports when Passthrough ->
[passthrough_stub(FuncArity) || FuncArity <- Exports];
- Exports when StubRet =:= undefined ->
- [];
- Exports when StubRet =:= true ->
- [void_stub(FuncArity, val(ok)) || FuncArity <- Exports];
+ Exports when StubAll ->
+ StubRet = case lists:keyfind(stub_all, 1, Options) of
+ {stub_all, RetSpec} -> RetSpec;
+ _ -> val(ok)
+ end,
+ [void_stub(FuncArity, StubRet) || FuncArity <- Exports];
Exports ->
- [void_stub(FuncArity, StubRet) || FuncArity <- Exports]
+ []
end,
dict:from_list(Expects).
View
27 test/meck_tests.erl
@@ -825,17 +825,9 @@ passthrough_bif_test() ->
?assertEqual(ok, meck:new(file, [unstick, passthrough])),
?assertEqual(ok, meck:unload(file)).
-stub_all_default_test() ->
- ok = meck:new(meck_test_module, [stub_all]),
- ok = meck:expect(meck_test_module, a, fun() -> c end),
- ?assertEqual(c, meck_test_module:a()),
- ?assertEqual(ok, meck_test_module:b()),
- ?assertEqual(ok, meck_test_module:c(1, 2)),
- ok = meck:unload(meck_test_module).
-
-stub_all_ret_spec_test() ->
+stub_all_test() ->
ok = meck:new(meck_test_module, [{stub_all, meck:seq([a, b])}]),
- ok = meck:expect(meck_test_module, a, fun() -> c end),
+ ok = meck:expect(meck_test_module, a, [], c),
?assertEqual(c, meck_test_module:a()),
?assertEqual(a, meck_test_module:b()),
?assertEqual(b, meck_test_module:b()),
@@ -845,6 +837,21 @@ stub_all_ret_spec_test() ->
?assertEqual(b, meck_test_module:c(1, 2)),
ok = meck:unload(meck_test_module).
+stub_all_default_test() ->
+ ok = meck:new(meck_test_module, [stub_all]),
+ ?assertEqual(ok, meck_test_module:c(1, 2)),
+ ok = meck:unload(meck_test_module).
+
+stub_all_undefined_test() ->
+ ok = meck:new(meck_test_module, [{stub_all, undefined}]),
+ ?assertEqual(undefined, meck_test_module:c(1, 2)),
+ ok = meck:unload(meck_test_module).
+
+stub_all_true_test() ->
+ ok = meck:new(meck_test_module, [{stub_all, true}]),
+ ?assertEqual(true, meck_test_module:c(1, 2)),
+ ok = meck:unload(meck_test_module).
+
stub_all_overridden_by_passthrough_test() ->
ok = meck:new(meck_test_module, [stub_all, passthrough]),
?assertEqual(a, meck_test_module:a()),

0 comments on commit d690ad4

Please sign in to comment.
Something went wrong with that request. Please try again.