View Source Patch.Mock.Server (patch v0.14.0)

Link to this section Summary

Types

Sum-type of all valid options

t()

Functions

Returns a specification to start this module under a supervisor.

Delegates a call to a mocked module through the server so it can optionally respond with a mock value.

Retrieves the call history for a mock

Callback implementation for GenServer.init/1.

Registers a mock value to be returned whenever the specified function is called on the module.

Restores a module to its original state.

Restores a function in a module to its original state

Link to this section Types

@type option() :: Patch.Mock.option()

Sum-type of all valid options

@type t() :: %Patch.Mock.Server{
  history: Patch.Mock.History.t(),
  mocks: %{required(atom()) => term()},
  module: module(),
  options: [Patch.Mock.Code.option()],
  unit: Patch.Mock.Code.Unit.t()
}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delegate(module, name, arguments)

View Source
@spec delegate(module :: module(), name :: atom(), arguments :: [term()]) :: term()

Delegates a call to a mocked module through the server so it can optionally respond with a mock value.

@spec expose(module :: module(), exposes :: Patch.Mock.exposes()) ::
  :ok | {:error, term()}
@spec history(module :: module()) :: Patch.Mock.History.t()

Retrieves the call history for a mock

@spec init(t()) :: {:ok, t()}

Callback implementation for GenServer.init/1.

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 to be returned whenever the specified function is called on the module.

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

Restores a module to its original state.

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

Restores a function in a module to its original state

Link to this function

start_link(module, options \\ [])

View Source
@spec start_link(module :: module(), options :: [Patch.Mock.Code.option() | option()]) ::
  {:ok, pid()} | {:error, {:already_started, pid()}}