FauxRedis.MockRule (faux_redis v1.0.3)

Copy Markdown View Source

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.

t()

A mock rule.

Functions

Builds a rule from a keyword list.

Types

kind()

@type kind() :: :stub | :expect

Rule type: stub or expectation.

matcher()

@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.

response_spec()

@type response_spec() :: FauxRedis.response_spec()

Response specification; see t:FauxRedis.response_spec.

t()

@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 reference
  • kind:stub or :expect
  • matcher – how commands are matched
  • respond – 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 applied
  • conn_ids – optional list of allowed connection ids

Functions

build(kind, opts)

@spec build(kind(), Keyword.t()) :: t()

Builds a rule from a keyword list.

Supported options:

  • :matcher – required matcher
  • :respond – required response specification
  • :kind:stub or :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