AssertMatch (assert_match v1.0.0)
Provides pipe-friendly assert_match/2
Link to this section Summary
Functions
Pipe-friendly equality/matching assertion.
Link to this section Functions
Pipe-friendly equality/matching assertion.
Performs:
=~
for Regex patterns=
for other patterns
extraction-of-pinned-function-calls
Extraction of pinned function calls
Elixir's ^/1
(pin operator) usually does not allow runtime function calls,
and only accepts previously bound user variables.
However, this macro "extracts" runtime function calls on pins in the pattern
and bind their results to temporary variables named pinned__<n>
(where <n>
is unique integer) so that you can actually write
function calls with pins! (Just like you do with Ecto.Query
)
With this you are now able to write test expressions like so:
conn
|> post("/some/api")
|> json_response(200)
|> assert_match(%{
"success" => true,
"id" => ^context.some_fixture.id,
"bytesize" => ^byte_size(context.some_fixture.contents)
})
You cannot nest pinned expressions. See test/assert_match_test.exs for more usages.