View Source Patch.Mock (patch v0.14.0)

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

Expose private functions in a module.

Gets the call history for a module.

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

@type 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.
@type exposes_option() :: {:exposes, exposes()}

The exposes option controls if any private functions should be exposed.

The default is :public.

Link to this type

history_limit_option()

View Source
@type 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.

@type option() :: exposes_option() | history_limit_option()

Sum-type of all valid options

Link to this section Functions

@spec expose(module :: module(), exposes :: exposes()) :: :ok | {:error, term()}

Expose private functions in a module.

If the module is not already mocked, calling this function will mock it.

@spec 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.

Link to this function

module(module, options \\ [])

View Source
@spec module(module :: module(), options :: [option()]) ::
  {:ok, pid()} | {:error, term()}

Mocks the given module.

Mocking a module accepts two options, see the option/0 type in this module for details.

Link to this function

register(module, name, value)

View Source
@spec 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.

@spec restore(module :: module()) :: :ok

Restores a module to pre-patch functionality.

If the module is not already mocked, this function no-ops.

@spec restore(mdoule :: module(), name :: atom()) :: :ok

Restores a function in a module to pre-patch functionality.

If the module or function are not already mocked, this function no-ops.