AssertMatch (assert_match v1.0.0)

Provides pipe-friendly assert_match/2

Link to this section Summary


Pipe-friendly equality/matching assertion.

Link to this section Functions

Link to this macro

assert_match(subject, pattern)


Pipe-friendly equality/matching assertion.


  • =~ for Regex patterns
  • = for other patterns


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:

|> post("/some/api")
|> json_response(200)
|> assert_match(%{
  "success" => true,
  "id" => ^,
  "bytesize" => ^byte_size(context.some_fixture.contents)

You cannot nest pinned expressions. See test/assert_match_test.exs for more usages.