Patch.Mock (patch v0.6.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

Checks to see if a function with the given name has been called in the given module.

Checks to see if a fucntion with the given name has been called in the given module with the given arguments.

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.

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.

Link to this type

history_limit_option()

View Source

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

Sum-type of all valid options

Link to this section Functions

Specs

called?(module :: module(), name :: atom()) :: boolean()

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.

Link to this function

called?(module, name, arguments)

View Source

Specs

called?(module :: module(), name :: atom(), arguments :: [term()]) :: boolean()

Checks to see if a fucntion with the given name has been called in the given module with the given arguments.

The arguments list can include the wildcard atom, :_ to match any argument in that position.

This function uses the Mock's history to check, if the history is limited or disabled then calls tht have happened may report back as never having happened.

Specs

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.

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.

Link to this function

module(module, options \\ [])

View Source

Specs

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

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.