Skip to content
Permalink
Browse files
Validate the options being passed to meck:new (#204)
* Validate the options being passed
* Add a new test for validate_options
* Fix a typo of passthrough option in a test case
  • Loading branch information
FrankBro authored and eproxus committed Mar 21, 2019
1 parent aefdac8 commit 2c7ba603416e95401500d7e116c5a829cb558665
Showing 3 changed files with 26 additions and 1 deletion.
@@ -193,8 +193,24 @@ stop(Mod) ->
%%% gen_server callbacks
%%%============================================================================

%% @hidden
validate_options([]) -> ok;
validate_options([no_link|Options]) -> validate_options(Options);
validate_options([spawn_opt|Options]) -> validate_options(Options);
validate_options([unstick|Options]) -> validate_options(Options);
validate_options([no_passthrough_cover|Options]) -> validate_options(Options);
validate_options([merge_expects|Options]) -> validate_options(Options);
validate_options([enable_on_load|Options]) -> validate_options(Options);
validate_options([passthrough|Options]) -> validate_options(Options);
validate_options([no_history|Options]) -> validate_options(Options);
validate_options([non_strict|Options]) -> validate_options(Options);
validate_options([stub_all|Options]) -> validate_options(Options);
validate_options([{stub_all, _}|Options]) -> validate_options(Options);
validate_options([UnknownOption|_]) -> erlang:error({bad_arg, UnknownOption}).

%% @hidden
init([Mod, Options]) ->
validate_options(Options),
Exports = normal_exports(Mod),
WasSticky = case proplists:get_bool(unstick, Options) of
true -> {module, Mod} = code:ensure_loaded(Mod),
@@ -163,7 +163,7 @@ result_different_caller() ->

history_kept_while_reloading() ->
NumCalls = 10,
meck:new(historical, [non_strict, passtrough]),
meck:new(historical, [non_strict, passthrough]),
meck:expect(historical, test_fn, fun(Arg) -> {mocked, Arg} end),
Test = self(),
Caller = spawn(fun() ->
@@ -811,6 +811,15 @@ expect_ret_specs_(Mod) ->

%% --- Tests with own setup ----------------------------------------------------

validate_options_test() ->
Mod = validate_options,
try
meck:new(Mod, passthrought),
throw(failed)
catch
error:function_clause -> ok
end.

merge_expects_module_test() ->
Mod = merge_mod,
meck:new(Mod, [non_strict, merge_expects]),

0 comments on commit 2c7ba60

Please sign in to comment.