Behat / Gherkin

Gherkin parser, written in PHP for Behat project
MIT License
1.05k stars 89 forks source link

Add Rule keyword support #246

Closed unkind closed 2 years ago

unkind commented 2 years ago

Hi,

PR provides the Rule keyword support (https://cucumber.io/docs/gherkin/reference/#rule).

ciaranmcnulty commented 2 years ago

I really want this feature, looking forward to reviewing it

unkind commented 2 years ago

This one still doesn't work: 'complex_background.feature' => 'Rule keyword not supported',.

It turns out Scenario and Scenario Outline have the same node type in Cucumber:

Feature: Complex background

  ...

  Rule: My Rule
    Scenario: with examples
      Given the <value> minimalism

      Examples:
      | value |
      | 1     |
      | 2     |
ciaranmcnulty commented 2 years ago

@pamil @stof we need to consider how Behat will adapt to this change. It'll impact tagging, running and a lot more.

  1. We could do it in a minor version of behat/gherkin with BC layers, then Behat can do some conditional logic to see if the parser supports rules

    • Quite a 'safe' option
    • Could enable a situation where a user has a Rule-aware Gherkin but not a Rule-aware Behat and therefore rules aren't a parse error, but are ignored by the runner
  2. We could do it in a major, expand Behat's supported versions, and have similar conditional logic

    • Guarantees Behat understands rules if they're parsed
    • Probably messier conditional logic in Behat if we didn't put in a BC layer
  3. We could do it in a major and bump Behat's dependency overnight

    • Guarantees Behat understands rules if they're parsed
    • No BC issues
    • Could conflict on codebases that use e.g. Codeception+Behat (does that happen?)
unkind commented 2 years ago

I found inconsistency with https://github.com/cucumber/common:

Feature: Some rules

  Background:
    Given fb

  Rule: A
    The rule A description

    Background:
      Given ab

    Example: Example A
      Given a

That parser doesn't remove indentation of description:

"description":"    The rule A description"

We can keep indentation data in FeatureNode, RuleNode, etc. and provide 2 methods: getDescription() and getRawDescription().

unkind commented 2 years ago

245 is just better way for this.