View Source Mockery.Assertions (mockery v2.3.3)

Set of additional assertion functions.

NOTE: Mockery doesn't keep track of function calls:

  • on modules that weren't prepared by Mockery.of/2 or Mockery.Macro.mockable/2

  • for MIX_ENV other than :test

  • for function called outside of test process (in spawned Task, GenServer etc.)

Summary

Functions

Asserts that function from given module with given name or name and arity was called at least once.

Asserts that function from given module with given name was called at least once with arguments matching given pattern.

Asserts that function from given module with given name was called given number of times with arguments matching given pattern.

Asserts that function from given module with given name or name and arity was NOT called.

Asserts that function from given module with given name was NOT called with arguments matching given pattern.

Asserts that function from given module with given name was NOT called given number of times with arguments matching given pattern.

Functions

Asserts that function from given module with given name or name and arity was called at least once.

Examples

Assert Mod.fun/2 was called

assert_called Mod, fun: 2

Assert any function named :fun from module Mod was called

assert_called Mod, :fun
Link to this macro

assert_called(mod, fun, args)

View Source (macro)

Asserts that function from given module with given name was called at least once with arguments matching given pattern.

Examples

Assert Mod.fun/2 was called with given args list

assert_called Mod, :fun, ["a", "b"]

You can also use unbound variables inside args pattern

assert_called Mod, :fun, ["a", _second]
Link to this macro

assert_called(mod, fun, args, times)

View Source (macro)

Asserts that function from given module with given name was called given number of times with arguments matching given pattern.

Similar to assert_called/3 but instead of checking if function was called at least once, it checks if function was called specific number of times.

Examples

Assert Mod.fun/2 was called with given args 5 times

assert_called Mod, :fun, ["a", "b"], 5

Assert Mod.fun/2 was called with given args from 3 to 5 times

assert_called Mod, :fun, ["a", "b"], 3..5

Assert Mod.fun/2 was called with given args 3 or 5 times

assert_called Mod, :fun, ["a", "b"], [3, 5]

Asserts that function from given module with given name or name and arity was NOT called.

Examples

Assert Mod.fun/2 wasn't called

refute_called Mod, fun: 2

Assert any function named :fun from module Mod wasn't called

refute_called Mod, :fun
Link to this macro

refute_called(mod, fun, args)

View Source (macro)

Asserts that function from given module with given name was NOT called with arguments matching given pattern.

Examples

Assert Mod.fun/2 wasn't called with given args list

refute_called Mod, :fun, ["a", "b"]

You can also use unbound variables inside args pattern

refute_called Mod, :fun, ["a", _second]
Link to this macro

refute_called(mod, fun, args, times)

View Source (macro)

Asserts that function from given module with given name was NOT called given number of times with arguments matching given pattern.

Similar to refute_called/3 but instead of checking if function was called at least once, it checks if function was called specific number of times.

Examples

Assert Mod.fun/2 was not called with given args 5 times

refute_called Mod, :fun, ["a", "b"], 5

Assert Mod.fun/2 was not called with given args from 3 to 5 times

refute_called Mod, :fun, ["a", "b"], 3..5

Assert Mod.fun/2 was not called with given args 3 or 5 times

refute_called Mod, :fun, ["a", "b"], [3, 5]