Definition of a single mock or expectation rule.
Rules are stored and evaluated by FauxRedis.MockEngine. Users normally
create rules via the high-level FauxRedis.stub/2, stub/3 and
FauxRedis.expect/3 functions.
Summary
Types
Rule type: stub or expectation.
Matcher used to decide which commands a rule applies to.
Response specification; see t:FauxRedis.response_spec.
A mock rule.
Functions
Builds a rule from a keyword list.
Types
@type kind() :: :stub | :expect
Rule type: stub or expectation.
@type matcher() :: FauxRedis.matcher() | {:command, FauxRedis.command_name(), [binary() | :any | Regex.t()]} | {:fn, (FauxRedis.Command.t() -> boolean())}
Matcher used to decide which commands a rule applies to.
@type response_spec() :: FauxRedis.response_spec()
Response specification; see t:FauxRedis.response_spec.
@type t() :: %FauxRedis.MockRule{ conn_ids: nil | [non_neg_integer()], id: reference(), kind: kind(), matcher: matcher(), max_calls: non_neg_integer() | :infinity, respond: response_spec(), times_used: non_neg_integer() }
A mock rule.
Fields:
id– unique referencekind–:stubor:expectmatcher– how commands are matchedrespond– response specification (or list of them for sequences)max_calls– maximum times this rule may be used (default::infinity)times_used– how many times the rule has been appliedconn_ids– optional list of allowed connection ids
Functions
Builds a rule from a keyword list.
Supported options:
:matcher– required matcher:respond– required response specification:kind–:stubor:expect:max_calls– maximum times this rule may be used:conn_id– only apply to the given connection id:conn_ids– only apply to any of the given connection ids