Gherkin.Parser (Cucumber v1.0.0)
View SourceGherkin parser using NimbleParsec.
This module parses Gherkin feature files into Elixir structs, supporting:
- Feature with name, description, and tags
- Background with steps
- Scenarios with steps and tags
- Scenario Outlines with Examples
- Steps with keywords, text, docstrings, and datatables
It implements a subset of the Gherkin language focused on core BDD concepts.
Summary
Functions
Parses a Gherkin feature file from a string into structured data.
Parses feature file content, choosing the parser by the file's path.
Functions
@spec parse(String.t()) :: Gherkin.Feature.t()
Parses a Gherkin feature file from a string into structured data.
This function takes a string containing Gherkin syntax and parses it into a
structured Gherkin.Feature struct with its associated components.
Parameters
gherkin_string- A string containing Gherkin syntax
Returns
Returns a %Gherkin.Feature{} struct containing:
name- The feature namedescription- The feature descriptiontags- List of feature-level tagsbackground- Background steps (if present)scenarios- List of scenarios
Examples
# Parse a string containing Gherkin syntax
Gherkin.Parser.parse("Feature: Shopping Cart\nScenario: Adding an item")
# Returns %Gherkin.Feature{} struct with parsed data
@spec parse(String.t(), String.t()) :: Gherkin.Feature.t()
Parses feature file content, choosing the parser by the file's path.
.feature.md files parse as Markdown with Gherkin (see
Gherkin.Markdown); everything else parses as plain Gherkin, exactly
like parse/1.
Examples
Gherkin.Parser.parse("# Feature: Cheese", "cheese.feature.md")
# Returns %Gherkin.Feature{} struct with parsed data