Declarative matchers for use with expect/2, refute_message/3, and
expect_sequence/2.
Each matcher function returns a predicate fn value -> boolean end that can
be passed directly to any DSL assertion:
expect "/robot/state",
matches(%{
mode: :running,
speed: gt(0),
battery: between(20, 100)
})Note on not/1
not/1 shadows Kernel.not/1. Add the following to your test module if you
also need Kernel's boolean not:
import Kernel, except: [not: 1]
Summary
Functions
Match lists where every element satisfies matcher.
Match lists where at least one element satisfies matcher.
Match numeric values within delta of n (default delta: 1.0e-6).
Match values in the inclusive range [low, high].
Match strings containing substring, or lists containing element.
Match empty enumerables or strings.
Match values strictly greater than n.
Match values greater than or equal to n.
Match the value false exactly.
Match nil.
Match the value true exactly.
Match values strictly less than n.
Match values less than or equal to n.
Match a struct or map against a spec map.
Invert a matcher.
Match values that are NOT a member of list.
Match non-empty enumerables or strings.
Match any non-nil value.
Match values that are a member of list.
Wrap a custom predicate as a matcher (identity — the predicate is already a matcher).
Functions
Match lists where every element satisfies matcher.
Match lists where at least one element satisfies matcher.
Match numeric values within delta of n (default delta: 1.0e-6).
approx(42.0)
approx(42.0, delta: 0.01)
Match values in the inclusive range [low, high].
Match strings containing substring, or lists containing element.
contains("mission") # string substring check
contains(:obstacle) # list membership check
Match empty enumerables or strings.
Match values strictly greater than n.
Match values greater than or equal to n.
Match the value false exactly.
Match nil.
Match the value true exactly.
Match values strictly less than n.
Match values less than or equal to n.
Match a struct or map against a spec map.
Each key in spec must exist in the value. Map values that are matcher
functions are applied; plain values are compared with ==.
matches(%{mode: :running})
matches(%{speed: gt(0), battery: between(20, 100)})
matches(%{pose: matches(%{x: approx(10.0, delta: 0.1)})})
Invert a matcher.
Match values that are NOT a member of list.
Match non-empty enumerables or strings.
Match any non-nil value.
Match values that are a member of list.
Wrap a custom predicate as a matcher (identity — the predicate is already a matcher).