mockery v1.1.0 Mockery.Assertions
This module contains a set of additional assertion functions.
Link to this section 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
Link to this section Functions
Asserts that function from given module with given name or name and arity was called at least once.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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
Asserts that function from given module with given name was called at least once with arguments matching given pattern.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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]
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.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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
Asserts that function from given module with given name was NOT called with arguments matching given pattern.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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]
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.
NOTE: Mockery doesn’t keep track of function calls on modules that
weren’t prepared by Mockery.of/2
and for MIX_ENV other than :test
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]