【问题标题】:Erlang Meck: How does one mock only a specific function clause?Erlang Meck:如何只模拟一个特定的函数子句?
【发布时间】:2017-07-25 06:45:43
【问题描述】:

给一个带有多个子句的函数,我只想模拟一个特定的情况,对于每个其他会导致“function_clause”错误的输入,我想让它由原始函数处理。这几乎就像 erlang meck 中的选择性直通。

【问题讨论】:

    标签: erlang meck


    【解决方案1】:

    你需要使用meck:passthrough/1: 我创建了一个具有如下功能的模块:

    -module(demo).
    -export([original/1]).
    
    original(1) -> one;
    original(2) -> two;
    original(3) -> three.
    

    然后在控制台上……

    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
    

    希望这会有所帮助:)

    【讨论】:

    • 如何使用meck绕过外键约束
    • 什么是“外键约束”?
    猜你喜欢
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2021-02-22
    • 2015-03-20
    相关资源
    最近更新 更多