Patch.Assertions (patch v0.7.0) View Source

Link to this section Summary

Functions

Asserts that the given module and function has been called with any arity.

Given a call will assert that a matching call was observed by the patched function.

Given a call will assert that a matching call was observed exactly the number of times provided by the patched function.

Given a call will assert that a matching call was observed exactly once by the patched function.

Refutes that the given module and function has been called with any arity.

Given a call will refute that a matching call was observed by the patched function.

Given a call will refute that a matching call was observed exactly the number of times provided by the patched function.

Given a call will refute that a matching call was observed exactly once by the patched function.

Link to this section Functions

Link to this function

assert_any_call(module, function)

View Source

Specs

assert_any_call(module :: module(), function :: atom()) :: nil

Asserts that the given module and function has been called with any arity.

patch(Example, :function, :patch)

Patch.Assertions.assert_any_call(Example, :function)   # fails

Example.function(1, 2, 3)

Patch.Asertions.assert_any_call(Example, :function)   # passes

There is a convenience delegate in the Developer Interface, Patch.assert_any_call/2 which should be preferred over calling this function directly.

Link to this function

assert_called(module, function, arguments)

View Source

Specs

assert_called(module :: module(), function :: atom(), arguments :: [term()]) ::
  nil

Given a call will assert that a matching call was observed by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.assert_called(Example, :function, [1, 2, 3])   # passes
Patch.Assertions.assert_called(Example, :function, [1, :_, 3])  # passes
Patch.Assertions.assert_called(Example, :function, [4, 5, 6])   # fails
Patch.Assertions.assert_called(Example, :function, [4, :_, 6])  # fails

There is a convenience macro in the Developer Interface, Patch.assert_called/1 which should be preferred over calling this function directly.

Link to this function

assert_called(module, function, arguments, count)

View Source

Specs

assert_called(
  module :: module(),
  function :: atom(),
  arguments :: [term()],
  count :: non_neg_integer()
) :: nil

Given a call will assert that a matching call was observed exactly the number of times provided by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.assert_called(Example, :function, [1, 2, 3], 1)   # passes
Patch.Assertions.assert_called(Example, :function, [1, :_, 3], 1)  # passes

Example.function(1, 2, 3)

Patch.Assertions.assert_called(Example, :function, [1, 2, 3], 2)   # passes
Patch.Assertions.assert_called(Example, :function, [1, :_, 3], 2)  # passes

There is a convenience macro in the Developer Interface, Patch.assert_called/2 which should be preferred over calling this function directly.

Link to this function

assert_called_once(module, function, arguments)

View Source

Specs

assert_called_once(
  module :: module(),
  function :: atom(),
  arguments :: [term()]
) :: nil

Given a call will assert that a matching call was observed exactly once by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.assert_called_once(Example, :function, [1, 2, 3])   # passes
Patch.Assertions.assert_called_once(Example, :function, [1, :_, 3])  # passes

Example.function(1, 2, 3)

Patch.Assertions.assert_called_once(Example, :function, [1, 2, 3])   # fails
Patch.Assertions.assert_called_once(Example, :function, [1, :_, 3])  # fails

There is a convenience macro in the Developer Interface, Patch.assert_called_once/1 which should be preferred over calling this function directly.

Link to this function

refute_any_call(module, function)

View Source

Specs

refute_any_call(module :: module(), function :: atom()) :: nil

Refutes that the given module and function has been called with any arity.

patch(Example, :function, :patch)

Patch.Assertions.refute_any_call(Example, :function)   # passes

Example.function(1, 2, 3)

Patch.Assertions.refute_any_call(Example, :function)   # fails

There is a convenience delegate in the Developer Interface, Patch.refute_any_call/2 which should be preferred over calling this function directly.

Link to this function

refute_called(module, function, arguments)

View Source

Specs

refute_called(module :: module(), function :: atom(), arguments :: [term()]) ::
  nil

Given a call will refute that a matching call was observed by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.refute_called(Example, :function, [4, 5, 6])   # passes
Patch.Assertions.refute_called(Example, :function, [4, :_, 6])  # passes
Patch.Assertions.refute_called(Example, :function, [1, 2, 3])   # fails
Patch.Assertions.refute_called(Example, :function, [1, :_, 3])  # passes

There is a convenience macro in the Developer Interface, Patch.refute_called/1 which should be preferred over calling this function directly.

Link to this function

refute_called(module, function, arguments, count)

View Source

Specs

refute_called(
  module :: module(),
  function :: atom(),
  arguments :: [term()],
  count :: non_neg_integer()
) :: nil

Given a call will refute that a matching call was observed exactly the number of times provided by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.refute_called(Example, :function, [1, 2, 3], 2)   # passes
Patch.Assertions.refute_called(Example, :function, [1, :_, 3], 2)  # passes

Example.function(1, 2, 3)

Patch.Assertions.refute_called(Example, :function, [1, 2, 3], 1)   # passes
Patch.Assertions.refute_called(Example, :function, [1, :_, 3], 1)  # passes

There is a convenience macro in the Developer Interface, Patch.refute_called/2 which should be preferred over calling this function directly.

Link to this function

refute_called_once(module, function, arguments)

View Source

Specs

refute_called_once(
  module :: module(),
  function :: atom(),
  arguments :: [term()]
) :: nil

Given a call will refute that a matching call was observed exactly once by the patched function.

The call can use the special sentinal :_ as a wildcard match.

patch(Example, :function, :patch)

Example.function(1, 2, 3)

Patch.Assertions.refute_called_once(Example, :function, [1, 2, 3])   # fails
Patch.Assertions.refute_called_once(Example, :function, [1, :_, 3])  # fails

Example.function(1, 2, 3)

Patch.Assertions.refute_called_once(Example, :function, [1, 2, 3])   # passes
Patch.Assertions.refute_called_once(Example, :function, [1, :_, 3])  # passes

There is a convenience macro in the Developer Interface, Patch.refute_called_once/1 which should be preferred over calling this function directly.