watermelon v0.1.1 Watermelon.DSL
Module with helper functions for defining Gherkin steps.
Defining steps
There are 3 helper macros that allows you to define steps for your feature specs:
All with exactly the same syntax:
defgiven match(a, b) when "sum of {int} and {int}" do
{:ok, sum: a + b}
end
Syntax for when
part is identical with Watermelon.Expression.from/1
so you
can provide either Regex
or string. Matching groups are then the arguments
for match
function.
Context
Step definition can access and modify it's context which is a way to propagate values between different steps.
Return value can be one of:
true
:ok
- keyword list
- map
- tuple
{:ok, map() | keyword()}
In case of keyword list or map, the returned values will be merged into current
context. When it is :ok
or true
then the context will be left as is.
Context can be made available by using :context
option:
defwhen match(a) when "I multiply sum by {int}", context: ctx do
{:ok, result: a * ctx.sum}
end
TODO
- add support for data table
- add support for doc strings
Link to this section Summary
Link to this section Functions
defgiven(arg, options \\ [], list) (macro)
defthen(arg, options \\ [], list) (macro)
defwhen(arg, options \\ [], list) (macro)
register_step(map, type, expression)
register_step(Macro.Env.t(), atom(), Watermelon.Expression.t()) :: atom()
register_step(Macro.Env.t(), atom(), Watermelon.Expression.t()) :: atom()
Register new step function.
Returns function name that must be used in step definition.