dream_test/gherkin/types
Gherkin types for dream_test.
These are the data structures produced by the Gherkin parser and consumed by the feature/discovery APIs. Most users won’t construct them directly, but they’re useful when you’re integrating your own parser or tooling.
Example
Use this when building BDD suites (e.g. in a snippet tests() function).
keyword_to_string(Given)
|> should
|> be_equal("Given")
|> or_fail_with("expected Given")
Types
Background steps that run before each scenario.
A Background defines common setup steps that are executed before every scenario in the feature. It’s useful for shared preconditions.
Background steps run before each scenario, as if they were prepended.
Example
empty_background()
|> should
|> be_equal(Background(steps: []))
|> or_fail_with("expected empty background")
pub type Background {
Background(steps: List(Step))
}
Constructors
-
Background(steps: List(Step))
Examples table for Scenario Outline.
Provides data for parameterized scenarios. Each row generates a separate scenario instance with placeholders replaced by values.
Example
ExamplesTable(headers: ["quantity"], rows: [["1"], ["5"]])
|> should
|> be_equal(ExamplesTable(headers: ["quantity"], rows: [["1"], ["5"]]))
|> or_fail_with("expected ExamplesTable to be constructible")
pub type ExamplesTable {
ExamplesTable(headers: List(String), rows: List(List(String)))
}
Constructors
-
ExamplesTable(headers: List(String), rows: List(List(String)))Arguments
- headers
-
Column headers (e.g., [“quantity”, “product”])
- rows
-
Data rows, each containing values for all columns
A parsed Gherkin feature file.
A feature represents a complete .feature file containing:
- Metadata (name, description, tags)
- Optional background steps
- One or more scenarios
Example
let step = Step(keyword: Given, text: "I have 1 item", argument: None)
let scenario = Scenario(name: "Example scenario", tags: [], steps: [step])
Feature(
name: "Example feature",
description: None,
tags: [],
background: None,
scenarios: [scenario],
)
|> should
|> be_equal(
Feature(
name: "Example feature",
description: None,
tags: [],
background: None,
scenarios: [scenario],
),
)
|> or_fail_with("expected Feature to be constructible")
pub type Feature {
Feature(
name: String,
source: option.Option(String),
description: option.Option(String),
tags: List(String),
background: option.Option(Background),
scenarios: List(Scenario),
)
}
Constructors
-
Feature( name: String, source: option.Option(String), description: option.Option(String), tags: List(String), background: option.Option(Background), scenarios: List(Scenario), )Arguments
- name
-
The feature name (from the Feature: line)
- source
-
Optional source identifier (typically the .feature file path)
- description
-
Optional description text below the feature name
- tags
-
Tags applied to the feature (inherited by all scenarios)
- background
-
Optional background steps run before each scenario
- scenarios
-
The scenarios in this feature
A scenario within a feature.
There are two variants:
A Scenario has concrete step text; a ScenarioOutline is parameterized
with an examples table and uses <placeholder> values in step text.
Example
let step = Step(keyword: Given, text: "I have 1 item", argument: None)
Scenario(name: "Example scenario", tags: [], steps: [step])
|> should
|> be_equal(Scenario(name: "Example scenario", tags: [], steps: [step]))
|> or_fail_with("expected Scenario to be constructible")
pub type Scenario {
Scenario(name: String, tags: List(String), steps: List(Step))
ScenarioOutline(
name: String,
tags: List(String),
steps: List(Step),
examples: ExamplesTable,
)
}
Constructors
-
Scenario(name: String, tags: List(String), steps: List(Step))A standard scenario with fixed step values.
Arguments
- name
-
The scenario name
- tags
-
Tags applied to this scenario (e.g., @slow, @wip)
- steps
-
The steps to execute
-
ScenarioOutline( name: String, tags: List(String), steps: List(Step), examples: ExamplesTable, )A parameterized scenario expanded from examples.
Arguments
- name
-
The scenario outline name
- tags
-
Tags applied to this scenario outline
- steps
-
The step templates with
syntax - examples
-
The examples table for parameterization
A single step in a scenario.
Steps are the executable units of a scenario. Each step has:
- A keyword (Given/When/Then/And/But)
- Text describing the action
- Optional argument (DocString or DataTable)
Example
Step(keyword: Given, text: "I have 1 item", argument: None)
|> should
|> be_equal(Step(keyword: Given, text: "I have 1 item", argument: None))
|> or_fail_with("expected Step to be constructible")
pub type Step {
Step(
keyword: StepKeyword,
text: String,
argument: option.Option(StepArgument),
)
}
Constructors
-
Step( keyword: StepKeyword, text: String, argument: option.Option(StepArgument), )Arguments
- keyword
-
The step keyword (Given, When, Then, And, But)
- text
-
The step text after the keyword
- argument
-
Optional DocString or DataTable argument
Optional argument attached to a step.
Steps can have additional structured data:
DocString
Multi-line text enclosed in triple quotes:
In Dream Test these values are represented as DocString(...).
DataTable
Tabular data with pipe-delimited rows:
In Dream Test these values are represented as DataTable(...).
pub type StepArgument {
DocString(content: String, content_type: option.Option(String))
DataTable(rows: List(List(String)))
}
Constructors
-
DocString(content: String, content_type: option.Option(String))Multi-line text content.
content- The text between the triple quotescontent_type- Optional media type hint (e.g., “json”, “xml”)
-
DataTable(rows: List(List(String)))Tabular data as a list of rows. Each row is a list of cell values. The first row is typically headers.
Keywords that can start a step.
In Gherkin, each step begins with one of these keywords:
Given- Describes initial context/preconditionsWhen- Describes an actionThen- Describes an expected outcomeAnd/But- Continues the previous step type
When matching step definitions, And and But inherit the keyword
type from the previous step (e.g., And after Given is treated as Given).
pub type StepKeyword {
Given
When
Then
And
But
}
Constructors
-
Given -
When -
Then -
And -
But
Values
pub fn empty_background() -> Background
Create an empty background.
Useful as a default value or for testing.
Example
empty_background()
|> should
|> be_equal(Background(steps: []))
|> or_fail_with("expected empty background")
pub fn empty_examples() -> ExamplesTable
Create an empty examples table.
Useful as a default value or for testing.
Example
empty_examples()
|> should
|> be_equal(ExamplesTable(headers: [], rows: []))
|> or_fail_with("expected empty examples table")
pub fn keyword_from_string(
text text: String,
) -> option.Option(StepKeyword)
Parse a string to a StepKeyword.
Returns the keyword if recognized, or None for unknown strings.
Example
keyword_from_string("Then")
|> should
|> be_equal(Some(Then))
|> or_fail_with("expected Some(Then)")
pub fn keyword_to_string(keyword keyword: StepKeyword) -> String
Convert a StepKeyword to its string representation.
Example
keyword_to_string(Given)
|> should
|> be_equal("Given")
|> or_fail_with("expected Given")
pub fn resolve_keyword(
keyword keyword: StepKeyword,
previous previous: StepKeyword,
) -> StepKeyword
Resolve And/But to the effective keyword based on previous step.
In Gherkin, And and But inherit meaning from the previous step.
This function resolves them to their effective keyword type.
Example
resolve_keyword(And, Given)
|> should
|> be_equal(Given)
|> or_fail_with("expected And after Given to resolve to Given")