Copeiro (Copeiro v0.1.1) View Source

The Copeiro package provides assertion functions that will enhance your testing experience in Elixir

Link to this section Summary

Functions

Asserts that two lists matches

Link to this section Functions

Link to this macro

assert_lists(expr, opts \\ [])

View Source (macro)

Asserts that two lists matches

Examples

For the following examples left and right will be used to describe the expression assert_lists left OPERATOR right

All elements of left are also elements of right

  iex> assert_lists [1, 2] in [0, 2, 1, 3]
  true

  iex> assert_lists [{:a, 1}, {:c, 3}] in [{:a, 1}, {:b, 2}, {:c, 3}]
  true

left and right has no element in common

  iex> assert_lists [1, 2] not in [3, 4]
  true

  iex> assert_lists [%{c: 3}, %{d: 4}] not in [%{a: 1}, %{b: 2}]
  true

Asserts that two lists match in any order

  iex> assert_lists [1, 2, 3] == [2, 1, 3], any_order: true
  true

  iex> assert_lists [{:a, 0}, {:b, 1}, {:c, 3}] == [{:a, 0}, {:c, 3}, {:b, 1}], any_order: true
  true

Asserting lists of maps/structs

  iex> assert_lists [%{a: 1}, %{a: 2}] in [%{a: 1, b: 1}, %{a: 2, b: 2}, %{a: 3, b: 3}], keys: [:a]
  true

  iex> assert_lists [%{a: 1}, %{a: 2}] == [%{a: 2, b: 2}, %{a: 1, b: 1}], keys: [:a], any_order: true
  true