Skip to content

feat: Allow scenarios to start with When or Then directly#15

Open
Kahoulam wants to merge 2 commits into
marcglasberg:mainfrom
Kahoulam:feat/scenario-when-then
Open

feat: Allow scenarios to start with When or Then directly#15
Kahoulam wants to merge 2 commits into
marcglasberg:mainfrom
Kahoulam:feat/scenario-when-then

Conversation

@Kahoulam

Copy link
Copy Markdown
Contributor

feat: Allow scenarios to start with When or Then directly

Overview

This PR adds when() and then() methods to the BddScenario class, allowing scenarios to start directly with these keywords without requiring given() first. This aligns with standard Gherkin/Cucumber behavior where a scenario can begin with any step keyword.

Changes

  • Added when() method to BddScenario: Allows scenarios to start directly with a When step.
  • Added then() method to BddScenario: Allows scenarios to start directly with a Then step.
  • Refactored BddScenario to separate file: Extracted BddScenario from bdd_base.dart into bdd_scenario.dart as a part file, following the same pattern as BddFeature and BddBackground.
  • Added comprehensive doc comments: Added complete API documentation to bdd_scenario.dart with examples for all methods (given, note, when, then).
  • Added tests: Created test/src/core/bdd_scenario_test.dart to verify the new functionality works correctly.

Usage Example

// Starting with When (without Given)
Bdd(feature)
  .scenario('calculate sum')
  .when('I add 2 and 3')
  .then('the result should be 5');

// Starting with Then (without Given or When)
Bdd(feature)
  .scenario('result occurs')
  .then('success message appears');

// Traditional flow (still supported)
Bdd(feature)
  .scenario('login')
  .given('user is registered')
  .when('user logs in')
  .then('access granted');

Closes #14

Kahoulam added 2 commits May 12, 2026 13:57
…ng()

- Fix BddFramework.toString() to include Background when withFeature=true
- Remove redundant \n prefixes from given/when/then/examples in BddRunner.config
- Add Runner Config Integration tests for feature, example, and background
- Create bdd_feature_description_test.dart for description and userStory tests
- Refactor tests to use default config + runner config instead of custom config
- Add when() and then() methods to BddScenario class
- Extract BddScenario to separate bdd_scenario.dart part file
- Add comprehensive doc comments with examples
- Add bdd_scenario_test.dart for verification

Closes marcglasberg#14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Allow scenarios to start with When or Then

1 participant