Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Strict keywords matching #221

Open
vitalets opened this issue Sep 16, 2024 · 0 comments
Open

Feature: Strict keywords matching #221

vitalets opened this issue Sep 16, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@vitalets
Copy link
Owner

vitalets commented Sep 16, 2024

The problem
Currently, keywords Given, When, Then are just aliases for the same function. The keyword is not taken into account when searching for step definition by step text. Some users would like to enable strict matching and avoid ambiguity in feature files.

A solution
Provide an option to enable strict keywords matching. When enabled, the following code will throw an error.
Step definition:

Given(“I have {number} dollars”, () => { ... })

Feature:

  Scenario: a scenario
    Given I have 100 dollars
    When I win in a lottery
    Then I have 200 dollars   # <- will throw an error, b/c step is defined with Given

There were several discussions in Cucumber community. In general, many people voted for such option.

Rules applied in strict mode

  1. step text started with Given, When, Then matches only definitions with the corresponding keyword or with universal Step function
  2. step text started with And / But looks up the nearest full keyword (Given, When, Then) and then follows the rule 1
    • if the first step starts with And / But, it is treated as Given
  3. step text started with * matches definitions with any keyword

Option name

  • respectKeywordDefinition: true
  • strictKeywords: true
  • matchKeywords: true
  • keywordsMatch: true
@vitalets vitalets added the enhancement New feature or request label Sep 16, 2024
@vitalets vitalets pinned this issue Sep 16, 2024
vitalets added a commit that referenced this issue Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant