stubr v1.0.3 Stubr

This module contains functions that create stub modules.

The functions stub/1 and stub/2 create new modules based on a list of function representations.

The function stub/2 also accepts a module as an optional first parameter. In this case, it checks whether the function(s) you want to stub exist in that module. Otherwise, it raises an UndefinedFunctionError.

Summary

Types

Represents a function name

Represents a function. The first element is an atom that represents the function name. The second element is an anonymous function that defines the behaviour of the function

Functions

Creates a stub using a list of function representations

Creates a stub using a list of function representations and a module to check for function existance

Types

function_name :: atom

Represents a function name

function_representation :: {function_name, (... -> any)}

Represents a function. The first element is an atom that represents the function name. The second element is an anonymous function that defines the behaviour of the function

Functions

stub(function_reps)

Specs

stub([function_representation]) :: module | no_return

Creates a stub using a list of function representations.

Examples

iex> Stubr.stub([{:add, fn (i, 2) -> i + 2 end}]).add(3, 2)
5
stub(module, function_reps)

Specs

stub(module, [function_representation]) ::
  module |
  no_return

Creates a stub using a list of function representations and a module to check for function existance.

The module argument prevents the creation of invalid stubs by checking if the function representations are defined for that module. Otherwise, it returns an UndefinedFunctionError.

Examples

iex> Stubr.stub(String, [{:to_atom, fn ("hello") -> :hello end}]).to_atom("hello")
:hello