double v0.6.4 Double

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.

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

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

Types

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

Functions

allow(dbl, function_name)

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.

allow(dbl, function_name, func_opts)
allow(any, atom, function | [allow_option]) ::
  struct |
  map |
  atom
clear(dbl, function_name \\ nil)
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.

double()
double() :: map

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

double(source, opts \\ [verify: true])
double(struct, [double_option]) :: struct
double(atom, [double_option]) :: atom

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