2

Give a function with multiple clauses, I'd want to mock only a specific case and for every other input that would otherwise cause a 'function_clause' error, I'd want to have it handled by the original function. It's almost like a selective passthrough in erlang meck.

1 Answer 1

7

You need to use meck:passthrough/1: I created a module with a function like this:

-module(demo).
-export([original/1]).

original(1) -> one;
original(2) -> two;
original(3) -> three.

Then on the console…

1> meck:new(demo).
ok
2> meck:expect(demo, original,
2>             fun (1) -> not_one
2>               ; (Arg) -> meck:passthrough([Arg])
2>             end).
ok
3> demo:original(1).
not_one
4> demo:original(2).
two

Hope this helps :)

2
  • How to bypass the foreign key constraint using meck
    – Tab Key
    Jul 31, 2021 at 18:16
  • What's "the foreign key constraint"? Aug 10, 2021 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.