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
Specs
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.
Specs
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.
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.
Specs
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.
Specs
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.
Specs
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.
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.
Specs
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.