DoctestSetup v0.1.0 DoctestSetup View Source
Defines doctest setup callbacks.
Typically doctests work best for stateless functions. Including setup in the doctetst itself can sacrifice readability. DoctestSetup lets us move that setup out of our doctests and into our test cases.
Link to this section Summary
Functions
Defines a callback to be run before doctests, matching on the provided options.
Link to this section Functions
Defines a callback to be run before doctests, matching on the provided options.
This macro builds on ExUnit.Callbacks.setup/2
callbacks, so blocks should return the values
described in the Context
section of the ExUnit.Callbacks
docs.
The same doctest can be setup by multiple doctest_setup
blocks.
Options
The options listed are matched upon, so we can either pass in concrete values or match values out. Any doctests not matching on the provided options are skipped by the setup block.
:arity
- The arity of the target function. For moduledoc doctests, this will benil
.:context
- The context of the doctest. See Context.:module
- The module of the target function.:name
- The name of the target function. For moduledoc doctests, this will benil
.:ordinal
- Which doctest in the doctstring to setup. The first doctest in each docstring is0
, and each subsequent doctest's ordinal is 1 greater than the previous.
Example
defmodule MyAppTest do
use ExUnit.Case, async: true
use DoctestSetup
doctest MyApp
doctest_setup name: :hello do
# do something stateful
:ok
end
doctest_setup name: name, arity: arity do
# do something with name and arity
[value: value]
end
end