Patch.Mock (patch v0.10.1) View Source
Link to this section Summary
Types
What exposures should be made in a module.
The exposes option controls if any private functions should be exposed.
This history_limit option controls how large of a history a mock should store
Sum-type of all valid options
Functions
Returns the number of times a matching call has been observed
Checks to see if the call has been observed.
Checks to see if a function with the given name has been called in the given module.
Expose private functions in a module.
Gets the call history for a module.
Given a call finds the latest call that matched.
Decorates the history with whether or not the call in the history matches the provided call.
Returns all the calls in the history that match the provided call.
Mocks the given module.
Registers a mock value for a function.
Restores a module to pre-patch functionality.
Restores a function in a module to pre-patch functionality.
Link to this section Types
Specs
exposes() :: :all | :public | Patch.Mock.Code.exports()
What exposures should be made in a module.
:public
will only expose the public functions:all
will expose both public and private functions- A list of exports can be provided, they will be added to the
:public
functions.
Specs
exposes_option() :: {:exposes, exposes()}
The exposes option controls if any private functions should be exposed.
The default is :public
.
Specs
history_limit_option() :: {:history_limit, non_neg_integer() | :infinity}
This history_limit option controls how large of a history a mock should store
It defaults to :infinity
which will store an unlimited history.
Specs
option() :: exposes_option() | history_limit_option()
Sum-type of all valid options
Link to this section Functions
Specs
Returns the number of times a matching call has been observed
The call arguments support any valid patterns.
This function uses the Mock's history to check, if the history is limited or disabled then calls that have happened may report back as never having happened.
Specs
Checks to see if the call has been observed.
The call arguments support any valid patterns.
This function uses the Mock's history to check, if the history is limited or disabled then calls that have happened may report back as never having happened.
Specs
Checks to see if a function with the given name has been called in the given module.
This function uses the Mock's history to check, if the history is limited or disabled then calls that have happened may report back as never having happened.
Specs
Expose private functions in a module.
If the module is not already mocked, calling this function will mock it.
Specs
history(module :: module()) :: Patch.Mock.History.t()
Gets the call history for a module.
If the module is not already mocked, this function returns an empty new history.
Specs
Given a call finds the latest call that matched.
Returns {:ok, {function, arguments}}
if a matching call is found, false
otherwise.
Specs
Decorates the history with whether or not the call in the history matches the provided call.
Provided call arguments support any valid patterns.
Returns the calls descending (newest first) as a two-tuple in the form
{boolean(), {atom(), [term()]}}
The first element indicates whether the call matches the provided call.
The second element is a tuple of function name and arguments.
This macro uses the Mock's history to check, if the history is limited or disabled then calls that have happened may report back as never having happened.
Specs
Returns all the calls in the history that match the provided call.
Provided call arguments support any valid patterns.
Returns the calls descending (newest first) as the list of arguments in the call
This macro uses the Mock's history to check, if the history is limited or disabled then calls that have happened may report back as never having happened.
Specs
Mocks the given module.
Mocking a module accepts two options, see the option/0
type in this module for details.
Specs
register(module :: module(), name :: atom(), value :: Patch.Mock.Value.t()) :: :ok
Registers a mock value for a function.
If the module is not already mocked, this function will mock it with no private functions exposed.
Specs
restore(module :: module()) :: :ok
Restores a module to pre-patch functionality.
If the module is not already mocked, this function no-ops.
Specs
Restores a function in a module to pre-patch functionality.
If the module or function are not already mocked, this function no-ops.