View Source Double (double v0.8.2)

Double builds on-the-fly injectable dependencies for your tests. It does NOT override behavior of existing modules or functions. Double uses Elixir's built-in language features such as pattern matching and message passing to give you everything you would normally need a complex mocking tool for.

Link to this section Summary

Functions

Adds a stubbed function to the given map, struct, or module. Structs will fail if they are missing the key given for function_name. Modules will fail if the function is not defined.

Returns a specification to start this module under a supervisor.

Clears stubbed functions from a double. By passing no arguments (or nil) all functions will be cleared. A single function name (atom) or a list of function names can also be given.

Returns a map that can be used to setup stubbed functions.

Same as double/0 but can return structs and modules too

Callback implementation for GenServer.init/1.

Link to this section Types

Specs

allow_option() ::
  {:with, [...]}
  | {:returns, any()}
  | {:raises, String.t() | {atom(), String.t()}}

Specs

double_option() :: {:verify, true | false}

Link to this section Functions

Link to this function

allow(dbl, function_name)

View Source

Adds a stubbed function to the given map, struct, or module. Structs will fail if they are missing the key given for function_name. Modules will fail if the function is not defined.

Link to this function

allow(dbl, function_name, func_opts)

View Source

Specs

allow(any(), atom(), function() | [allow_option()]) :: struct() | map() | atom()

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

clear(dbl, function_name \\ nil)

View Source

Specs

clear(any(), atom() | list()) :: struct() | map() | atom()

Clears stubbed functions from a double. By passing no arguments (or nil) all functions will be cleared. A single function name (atom) or a list of function names can also be given.

Specs

double() :: map()

Returns a map that can be used to setup stubbed functions.

Link to this function

double(source, opts \\ [verify: true, send_stubbed_module: false])

View Source

Specs

double(struct(), [double_option()]) :: struct()
double(atom(), [double_option()]) :: atom()

Same as double/0 but can return structs and modules too

Callback implementation for GenServer.init/1.

Link to this function

stub(dbl, function_name, func)

View Source

Specs

stub(atom(), atom(), function()) :: atom()