Hegel.ExUnit (hegel_elixir v0.1.1)
View SourceExUnit integration for Hegel properties.
use Hegel.ExUnit sets up an ExUnit case, imports Hegel's generators, and
provides the property and check all macros.
The DSL follows StreamData's property and check all syntax:
property "reversing twice preserves a list" do
check all values <- list_of(integer()) do
assert values |> Enum.reverse() |> Enum.reverse() == values
end
endHegel evaluates generator clauses from left to right, so later generators can use earlier draws. A pattern mismatch or a false clause rejects the example as an assumption.
Summary
Functions
Sets up a module as an ExUnit case with Hegel's property-testing DSL.
Checks a property against values drawn from one or more generators.
Defines a pending property.
Defines an ExUnit property.
Functions
Sets up a module as an ExUnit case with Hegel's property-testing DSL.
Hegel passes all options to ExUnit.Case unless the module already uses it.
Checks a property against values drawn from one or more generators.
Generator clauses use <-. Later generators and clauses may use bindings
introduced by earlier clauses:
check all values <- list_of(integer()),
index <- integer(min: 0, max: max(length(values) - 1, 0)),
values != [],
selected = Enum.at(values, index),
test_cases: 250 do
assert selected in values
endA pattern mismatch or a false clause rejects the current test case through
Hegel.assume/3. Hegel passes the trailing keyword options to
Hegel.check/2.
check all derives :database_key from the caller module and property
function when you omit it, so stored counterexamples retain the same key
across runs.
Defines a pending property.
The ExUnit test receives :property and :not_implemented tags and fails
with "Not implemented".
Defines an ExUnit property.
Pass an optional context pattern as you would to ExUnit.Case.test/3:
property "uses setup data", %{account: account} do
check all suffix <- text() do
assert is_binary(account.name <> suffix)
end
end