View Source Euclid.Assertions (Euclid v0.4.0)

Some ExUnit assertions

Link to this section Summary

Functions

Asserts that the left and right values are equal. Returns the left value unless the assertion fails, or if the :returning option is used. Uses assert left == right under the hood, but works nicely in a pipeline.

Asserts that a NaiveDateTime or DateTime is no more than 30 seconds ago.

Asserts a pre-condition and a post-condition are true after performing an action.

Link to this section Types

Specs

assert_eq_opts() ::
  {:ignore_order, boolean()}
  | {:returning, any()}
  | {:within, number() | {number(), Euclid.Duration.time_unit()}}

Link to this section Functions

Link to this function

assert_datetime_approximate(left, right, delta \\ 1)

View Source
This function is deprecated. Use `assert_eq(left, right, within: {delta, unit})` instead.
Link to this function

assert_eq(left, right, opts \\ [])

View Source

Specs

assert_eq(left :: any(), right :: any(), opts :: [assert_eq_opts()]) :: any()

Asserts that the left and right values are equal. Returns the left value unless the assertion fails, or if the :returning option is used. Uses assert left == right under the hood, but works nicely in a pipeline.

Options:

  • ignore_order: boolean - if the left and right values are lists, ignores the order when checking equality.
  • returning: value - returns value if the assertion passes, rather than returning the left value.
  • within: delta - asserts that the left and right values are within delta of each other rather than strictly equal.
  • within: {delta, time_unit} - like within: delta but performs time comparisons in the specified time_unit. If left and right are strings, they are parsed as ISO8601 dates.
Link to this function

assert_recent(timestamp)

View Source

Asserts that a NaiveDateTime or DateTime is no more than 30 seconds ago.

Link to this macro

assert_that(command, list)

View Source (macro)

Specs

assert_that(any(), [{:changes, any()} | {:from, any()} | {:to, any()}, ...]) ::
  {:__block__, [], [...]}

Asserts a pre-condition and a post-condition are true after performing an action.

Examples

{:ok, agent} = Agent.start(fn -> 0 end)

assert_that(Agent.update(agent, fn s -> s + 1 end),
  changes: Agent.get(agent, fn s -> s end),
  from: 0,
  to: 1
)