View Source Patch.Assertions (patch v0.16.0)
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.
Functions
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) # passesThere 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.
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]) # failsThere is a convenience macro in the Developer Interface, Patch.assert_called/1 which should be
preferred over calling this macro directly.
@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) # passesThere is a convenience macro in the Developer Interface, Patch.assert_called/2 which
should be preferred over calling this macro directly.
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]) # failsThere is a convenience macro in the Developer Interface, Patch.assert_called_once/1 which
should be preferred over calling this macro directly.
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.
patch(Example, :function, :patch)
Patch.Assertions.refute_any_call(Example, :function) # passes
Example.function(1, 2, 3)
Patch.Assertions.refute_any_call(Example, :function) # failsThere 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.
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]) # passesThere is a convenience macro in the Developer Interface, Patch.refute_called/1 which should be
preferred over calling this macro directly.
@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) # passesThere is a convenience macro in the Developer Interface, Patch.refute_called/2 which
should be preferred over calling this macro directly.
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]) # passesThere is a convenience macro in the Developer Interface, Patch.refute_called_once/1 which
should be preferred over calling this macro directly.