Cucumber.ParameterTypes (Cucumber v1.0.0)

View Source

Defines 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/
end

Then use them in step definitions like any built-in type:

step "{flight} has been delayed", %{args: [flight]} do
  # flight is %{from: "LHR", to: "CDG"}
end

Options

  • :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 (nil for 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.

Functions

parameter_type(name, opts)

(macro)

Registers a custom parameter type. See the module documentation.