stubr v1.2.0 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
. Additionally, if the auto_stub option
is set to true, then it will defer all un-stubbed functions
to the original module.
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
Creates a stub using a list of function representations
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
Specs
stub!([function_representation]) ::
module |
no_return
Creates a stub using a list of function representations.
Examples
iex> Stubr.stub!([{:to_atom, fn ("foo") -> :stubbed end}]).to_atom("foo")
:stubbed
Specs
stub!(module, [function_representation]) ::
module |
no_return
Creates a stub using a list of function representations.
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 ("foo") -> :stubbed end}]).to_atom("foo")
:stubbed
Specs
stub!(module, [function_representation], [{:auto_stub, boolean}]) ::
module |
no_return
Creates a stub using a list of function representations.
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
.
If the auto_stub option is set to true, then it will defer all un-stubbed functions to the original module.
Examples
iex> Stubr.stub!(String, [{:to_atom, fn ("foo") -> :stubbed end}]).to_atom("foo")
:stubbed
iex> Stubr.stub!(String, [{:to_atom, fn ("foo") -> :stubbed end}], auto_stub: true).to_atom("bar")
:bar