Skip to content

Proposal: Unambiguous Keywords #768

@badeball

Description

@badeball

Proposal Summary / Motivation

I've briefly presented this idea on Slack and in the spirit of gathering more feedback I'm posting it here as well.

The Gherkin reference specifically stipulates that keywords should not be taken into account when looking for a step definition [1].

I've personally witnessed in several projects that this can lead to deterioration in test language unless every change is strictly reviewed.

Below is an example of a hastily written patch that breaks the flow of language, but doesn't yield an error (actually taken from my Git history, but modified slightly to anonymize the domain).

       When I press the foobar button
-      Then I should see 2 events in total
       And I should see these new fields with values
         | My Field      | foo |
         | Another Field | bar |

[1] https://cucumber.io/docs/gherkin/reference/#steps

Current Behavior

Currently, the following steps would yield ambiguity error.

• Given(“I press button”)
• When(“I press button”)

I don't propose changing this.

However, it doesn't matter which keyword you use in your feature files and the example below runs just fine.

# features/step_definitions/cucumber_steps.js
import {When} from 'cucumber'

When(/^a step$/, function() {});

# features/a.feature
Feature: a feature name
  Scenario: a scenario name
    Given a step

Proposed Behavior

Given the following step definitions.

When("step a", () => {});

... and the following feature file.

Feature: a feature name
  Scenario: a scenario name
    Given a step

I propose for Cucumber to fail with a wrong-keyword error. Furthermore, and just as importantly, for this to properly work, any use of And and But keyword must be interpreted as if they were of the same type as the previous step.

I've tried to outline this behavior with some test cases here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🧷 pinnedTells Stalebot not to close this issuemilestone-proposalCandidate for Cucumber cross-platform milestone

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions