Cucumber.ParameterTypes (Cucumber v1.0.0)
View SourceDefines custom parameter types for use in cucumber expressions.
Custom parameter types let step patterns use domain vocabulary like
{flight} with automatic transformation into domain values. Define them in
a support file (loaded before step definitions):
# test/features/support/parameter_types.exs
defmodule MyApp.ParameterTypes do
use Cucumber.ParameterTypes
parameter_type :flight,
regexp: ~r/([A-Z]{3})-([A-Z]{3})/,
transform: fn from, to -> %{from: from, to: to} end
parameter_type :color, regexp: ~r/red|blue|green/
endThen use them in step definitions like any built-in type:
step "{flight} has been delayed", %{args: [flight]} do
# flight is %{from: "LHR", to: "CDG"}
endOptions
:regexp(required) - the regex a value must match. It is matched against the step text at the parameter's position.:transform(optional) - a function converting the matched text into a value. With no capture groups in the regexp, it receives the full match; with capture groups, it receives one argument per group (nilfor unmatched optional groups). Without a transform, the parameter yields the full matched string.
Names must consist of lowercase letters and underscores, and cannot shadow
the built-in types (string, int, float, word, atom).
Summary
Functions
Registers a custom parameter type. See the module documentation.