Cucumber.StepDefinition (Cucumber v1.0.0)

View Source

Provides macros for defining cucumber step definitions.

Usage

defmodule AuthenticationSteps do
  use Cucumber.StepDefinition

  step "I am logged in as {string}", %{args: [username]} = context do
    {:ok, Map.put(context, :current_user, username)}
  end
end

Regular expression patterns

Steps can also be defined with a regular expression instead of a cucumber expression. The regex must match the entire step text, and capture groups arrive in context.args in order — always as strings (no type conversion), with nil for unmatched optional groups:

step ~r/^I have (\d+) cukes(?: in my (.+))?$/, %{args: [count, location]} = context do
  {:ok, Map.put(context, :cukes, {String.to_integer(count), location})}
end

Summary

Functions

step(pattern, context_var \\ {:_, [], nil}, list)

(macro)

Defines a step implementation.

The pattern is either a cucumber expression string or a regular expression (~r// sigil) — see the module documentation for the differences.