2 API Reference🔗ℹ
2.1 The feature Language🔗ℹ
Feature files use #lang feature and follow a
subset of the Gherkin
specification. The reader parses the file and provides a single binding:
features — a (listof gherkin-feature?) containing
the parsed feature structures. Require the ".feature" file
from a Racket module to access this binding.
The rackunit/feature module provides the two primary
entry points for defining and running BDD tests.
(define-steps name clause ...)
|
| |
| clause | | = | | (given pattern handler) | | | | | | | (when pattern handler) | | | | | | | (then pattern handler) | | | | | | | | pattern | | = | | string? | | | | | | | | handler | | = | | (-> hash? any/c ... hash?) |
|
Defines
name as a list of
step-def structures.
Each clause pairs a step keyword with a pattern and handler
function. The keywords given, when, and then
are matched by datum — they do not shadow racket/base’s
when.
The pattern is a string that may contain {placeholder}
markers. Each placeholder becomes a capture group. Captured values are
passed to the handler as strings after the context argument.
Builds
rackunit test suites from
features and
runs them.
An empty hash table is created, passed through before-all,
then threaded through features, scenarios, and steps. Each scenario
receives a fresh copy of the context from before-feature,
isolating scenarios from one another. Background steps (if any) run
before each scenario’s own steps.
See the Lifecycle Hooks section of the guide for the
full execution order.
These prefab structures represent parsed Gherkin documents.
They are produced by the #lang feature reader and
consumed by run-features.
The top-level container returned by the parser. Contains the list of
gherkin-feature structures found in the source file. Most users
interact with
features directly (as provided by
#lang feature) rather than the document wrapper.
A single Feature: block. The tags field contains tag
strings (e.g., "@smoke"). The background is a
(possibly empty) list of steps that run before every scenario.
A Scenario: or expanded Scenario Outline: instance. When
expanded from an outline, the name includes parameter values
(e.g., "Addition (a=1, b=2, result=3)").
A single step. The
type is one of
'given,
'when,
'then,
'and, or
'but.
The
argument is
#f when absent, a
(listof (listof string?)) for a data table, or a
string? for a doc string.
Lower-level utilities for step definition matching and execution.
A step definition binding a type ('given,
'when, or 'then), a pattern string (possibly
containing {placeholder} markers), and a handler
procedure.
Converts a step pattern to a compiled
regular expression. Each
{placeholder} becomes a
(.+?) non-greedy capture group, and
the result is anchored with
^ and
$.
Finds the first
step-def in
step-defs whose
type matches and whose
pattern matches
text,
then calls its handler with
ctx, captured values, and
(when non-
#f) the
argument.
Raises exn:fail? if no matching step definition is found.