double v0.4.0 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

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
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