View Source EfxCase.MockState (Efx v0.2.5)

This module implements a global mutable state needed for mocking.

Mocking works by adding the pid of the mock-owning process to it's dictionary and accessing this pid using a lookup with ProcessTree.

The pid then can be used to lookup information of the mock, e.g. which function is mocked with replacement or how often a function was called to verify. This module is the global lookup.

We need a global lookup in which we can manipulate data to count mock invocations as well as store mocks as global when a test is flagged as async.

Summary

Types

Defines the scopes of a binding.

Types

@type scope_t() :: pid() | :global | :omnipresent

Defines the scopes of a binding.

A scope is one of the following

  • pid: the binding is bound to a pid
  • global: the binding is bound globally, defined with async: true
  • omnipresent: the binding is omnipresent, that is, defined at test bootstrap

Functions

Link to this function

add_fun(pid, behaviour, fun_identifier, arity, fun, num_expected_calls)

View Source
@spec add_fun(
  scope_t(),
  module(),
  atom(),
  arity(),
  (... -> any()),
  non_neg_integer() | nil
) :: :ok
Link to this function

call(behaviour, fun_identifier, args)

View Source
@spec call(module(), atom(), [any()]) :: function_return :: any()
Link to this function

call(pid, behaviour, fun_identifier, args)

View Source
@spec call(scope_t() | nil, module(), atom(), [any()]) :: function_return :: any()

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec clean_after_test() :: :ok
@spec mocked?(module()) :: boolean()
@spec mocked?(scope_t(), module()) :: boolean()
@spec parse([EfxCase.Mock.MockedFun.t()]) :: String.t()
@spec verify_called!() :: no_return() | nil | :ok
@spec verify_called!(scope_t()) :: no_return() | nil | :ok