View Source Patch.Assertions (patch v0.13.0)

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.

Formats the AST for a list of patterns AST as they would appear in an argument list.

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
@spec 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 are convenience delegates in the Developer Interface, Patch.assert_any_call/1 and Patch.assert_any_call/2 which should be preferred over calling this function directly.

Link to this macro

assert_called(call)

View Source (macro)
@spec assert_called(call :: Macro.t()) :: Macro.t()

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

This macro fully supports patterns and will perform non-hygienic binding similar to ExUnit's assert_receive/3 and assert_received/2.

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 macro directly.

Link to this macro

assert_called(call, count)

View Source (macro)
@spec assert_called(call :: Macro.t(), count :: non_neg_integer()) :: Macro.t()

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

This macro fully supports patterns and will perform non-hygienic binding similar to ExUnit's assert_receive/3 and assert_received/2. The value bound will be the from the latest call.

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 macro directly.

Link to this macro

assert_called_once(call)

View Source (macro)
@spec assert_called_once(call :: Macro.t()) :: Macro.t()

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

This macro fully supports patterns and will perform non-hygienic binding similar to ExUnit's assert_receive/3 and assert_received/2.

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 macro directly.

Link to this macro

format_patterns(patterns)

View Source (macro)
@spec format_patterns(patterns :: [term()]) :: String.t()

Formats the AST for a list of patterns AST as they would appear in an argument list.

Link to this function

refute_any_call(module, function)

View Source
@spec 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 are convenience delegates in the Developer Interface, Patch.refute_any_call/1 and Patch.refute_any_call/2 which should be preferred over calling this function directly.

Link to this macro

refute_called(call)

View Source (macro)
@spec refute_called(call :: Macro.t()) :: Macro.t()

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

This macro fully supports patterns.

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 macro directly.

Link to this macro

refute_called(call, count)

View Source (macro)
@spec refute_called(call :: Macro.t(), count :: non_neg_integer()) :: Macro.t()

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

This macro fully supports patterns.

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 macro directly.

Link to this macro

refute_called_once(call)

View Source (macro)
@spec refute_called_once(call :: Macro.t()) :: Macro.t()

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

This macro fully supports patterns.

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 macro directly.