Support Gherkin Rule: (with optional Rule-level Background)

#1 · open · 0 comments

View on GitHub ↗

slagyr

## Summary Please add support for Gherkin **`Rule:`** sections, including optional **`Background:`** under a Rule. ## Motivation We use gherclj for requirements- and acceptance-level features (e.g. Tonotop). Features often need: - One **Feature Background** for shared cast/fixtures (clinic, default patient) - **Different path-in** for groups of scenarios (email channel vs claim vs recovery) Without `Rule:`, we only get a single Feature-level Background. Nested backgrounds are not possible, so either every scenario repeats path-in Givens or we split into many feature files. Gherkin 6+ allows: ```gherkin Feature: Patient onboarding Background: Given Horton Audiology uses Tonotop And JoJo Who is Horton's patient with email and phone on file Rule: Email invitation Background: # optional — runs after Feature Background for scenarios in this Rule only Given Horton has sent JoJo an email invitation Scenario: … Scenario: … Rule: Printed handout claim Background: Given Horton has given JoJo a printed handout Scenario: … ``` ## Current behavior (gherclj v1.3.0) The parser recognizes `Feature:`, `Background:`, `Scenario:`, `Scenario Outline:`, and `Examples:`, but not `Rule:`. A `Rule:` line is not treated as a structural keyword (no rule-scoped background or scenario grouping). ## Proposed behavior 1. Parse `Rule: <title>` (and optional description lines under it). 2. Scenarios / outlines under a Rule belong to that Rule. 3. Optional `Background:` immediately under a Rule applies only to scenarios in that Rule. 4. Execution order per scenario: **Feature Background → Rule Background (if any) → scenario steps** (same as Cucumber). 5. Tags on Rules apply to all scenarios in the Rule (if tag filtering is consistent with Feature-level tags). 6. Generated specs / `file:line` selection still work for scenarios inside Rules. 7. Document in README; add parser + generator tests. ## Out of scope (unless easy) - Nested Rules - Rule-only examples without scenarios ## Alternatives we use today - Scenario-level Givens for path-in - Multiple feature files - Overloading Feature Background (too broad) Happy to help with a PR or a failing feature fixture if useful. ## Context Requested from Tonotop requirements drafting (patient onboarding invitation features) where Feature Background holds shared patient fixture and section-specific path-in would map cleanly to Rules.

Comments