stubr v1.3.0 Stubr

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 accepts a list of options as an optional second parameter. The possible options are:

  • module - the module to stub. It will raise an UndefinedFunctionError if the module does not contain the function you want to stub.
  • auto_stub - if true, then if the module option is set, then it will defer all non-stubbed functions to the original module.
  • call_info - if true, then call info will be recorded by Stubr. This is accessed by calling the function __stubr__(:call_info: function_name).
  • behaviour - if set, then the stub will throw a compiler warning if it does not implement the behaviour.

Summary

Types

Represents a function. This is an anonymous function that defines the behaviour of the function

An atom, representing a function name

The options that can be passed into the stub! function

Types

function_implementation :: (... -> any)

Represents a function. This is an anonymous function that defines the behaviour of the function

function_name :: atom

An atom, representing a function name

stubr_options :: [auto_stub: boolean, module: module, behaviour: module, call_info: boolean]

The options that can be passed into the stub! function

Functions

stub!(functions, opts \\ [])

Specs

stub!([{function_name, function_implementation}], stubr_options) ::
  module |
  no_return

Creates a stub.

Examples

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