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

Nested rule doesn't consume all needed backgrounds #126

Closed
elchupanebrej opened this issue Jun 25, 2023 · 7 comments
Closed

Nested rule doesn't consume all needed backgrounds #126

elchupanebrej opened this issue Jun 25, 2023 · 7 comments

Comments

@elchupanebrej
Copy link

👓 What did you see?

feature = """
Feature: Nested rules
  Background:
    Given Feature background

  Rule: Outer rule
    Background:
      Given Outer rule background step

    Rule: Nested rule
      Background:
        Given Nested background rule step

      Example:
        Then Scenario step
"""

from gherkin.parser import Parser
from gherkin.pickles.compiler import Compiler
parser = Parser()
gherkin_document = parser.parse(feature)
gherkin_document["uri"] = 'local'
pickles = Compiler().compile(gherkin_document)

I get next pickle:

[{'astNodeIds': ['8'],
  'id': '3',
  'language': 'en',
  'name': '',
  'steps': [{'astNodeIds': ['0'],
             'id': '0',
             'text': 'Feature background',
             'type': 'Context'},
            {'astNodeIds': ['5'],
             'id': '1',
             'text': 'Nested background rule step',
             'type': 'Context'},
            {'astNodeIds': ['7'],
             'id': '2',
             'text': 'Scenario step',
             'type': 'Outcome'}],
  'tags': [],
  'uri': 'local'}]

so Outer rule background step is missing in the pickle

✅ What did you expect to see?

All 4 steps from every level background is present in the pickle

📦 Which tool/library version are you using?

Python 3.10.9
gherkin-official 24.1.0

This text was originally generated from a template, then edited by hand. You can modify the template here.

@luke-hill
Copy link
Contributor

I'm 95% certain we test this in our acceptance tests. However you are using quite an old version (So it maybe something we've only introduced recently).

I do know python is one of the versions that has slightly less usage, that might be why.

@mpkorstanje
Copy link
Contributor

A quick guess would be that we fixed this somewhere after the mono repo split. We haven't released the python module since. #148.

@elchupanebrej
Copy link
Author

gherkin-official 29.0 - Reproduced

@luke-hill
Copy link
Contributor

luke-hill commented Nov 18, 2024

My understanding is all Rule tags are considered top level. This is because you can't have 2 background references within a rule.

I would expect your sample to equate to

Test 1: Outer Rule: Given feature background / Given outer rule
Test 2: Inner Rule: Given feature background / Given Inner / Then scenario step

But I'm sure this may be something that I'm not 100% au faix with. It definitely should live in either gherkin testing as testdata golden or in the CCK proper. CCK currently has this: https://github.com/cucumber/compatibility-kit/blob/main/devkit/samples/rules/rules.feature

Rule has this: https://github.com/cucumber/gherkin/blob/main/testdata/good/rule.feature

Because the concept of tabbing in gherkin isn't concrete, I would say that your tabbing here a misnomer and based on the tests written above, that my understanding is probably what is happening. Can you confirm this?

@elchupanebrej
Copy link
Author

@luke-hill Thank you for your explanation. It seems that nested rules are not supported. I expected that rules could be deeply nested and that every rule would add its own background at the top of the example steps.

@luke-hill
Copy link
Contributor

Let's close this as not a bug then

@luke-hill
Copy link
Contributor

@elchupanebrej - Ironically I found a long standing issue to update the docs that would cover this situation here: cucumber/docs#561 I never got around to doing it though

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

No branches or pull requests

3 participants