kale v0.5.1 Kale.FeatureCase
An ExUnit
test case for writing features using Kale.
Usage
defmodule MyTest do
use Kale.FeatureCase, async: true
feature "Feature description here" do
scenario "Scenario description here", """
Given some precondition
When action {foo} happens
Then the result is {bar}
"""
defgiven "some precondition" do
# ...
end
defwhen "action {action} happens" do
# interpolated variables are magically available
result = do_something(action)
# if the step returns a map, it will be merged with the test context
%{result: result}
end
defthen "the result is {expected}", %{result: result} do
# Optional second argument for context, as per standard ExUnit
assert result == expected
end
end
Each feature
generates a describe
, and each scenario
a test
. Standard
ExUnit features such as setup
can be used as normal.
To avoid the formatter inserting extra parens, you can specify import_deps: [:kale]
in your .formatter.exs
.
Link to this section Summary
Functions
Generate a step definition matching a particular string and optionally a context map. See the module documentation for usage examples.
An alias for defgiven/2
.
An alias for defgiven/2
.
Generate a feature block, which corresponds to an ExUnit describe
.
Generate a scenario block, which corresponds to an ExUnit test
.
Link to this section Functions
defgiven(step, context \\ {:%{}, [], []}, list) (macro)
Generate a step definition matching a particular string and optionally a context map. See the module documentation for usage examples.
The given, when and then steps are actually interchangeable – the separate macros are provided for readability only.
defthen(step, context \\ {:%{}, [], []}, list) (macro)
An alias for defgiven/2
.
defwhen(step, context \\ {:%{}, [], []}, list) (macro)
An alias for defgiven/2
.
feature(name, list) (macro)
Generate a feature block, which corresponds to an ExUnit describe
.
scenario(name, body) (macro)
Generate a scenario block, which corresponds to an ExUnit test
.