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

Add Rule keyword support #246

Closed
wants to merge 1 commit into from
Closed

Conversation

unkind
Copy link
Contributor

@unkind unkind commented Nov 5, 2021

Hi,

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

@ciaranmcnulty
Copy link
Contributor

I really want this feature, looking forward to reviewing it

@unkind unkind changed the title Add Rule keyword support [WIPAdd Rule keyword support Nov 5, 2021
@unkind unkind changed the title [WIPAdd Rule keyword support [WIP] Add Rule keyword support Nov 5, 2021
@unkind unkind force-pushed the feature-rule-keyword branch 2 times, most recently from 5b2499a to 2ee0f1e Compare November 5, 2021 17:27
@unkind unkind force-pushed the feature-rule-keyword branch from 2ee0f1e to f77b8d9 Compare November 5, 2021 17:31
@unkind
Copy link
Contributor Author

unkind commented Nov 5, 2021

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     |

@unkind unkind changed the title [WIP] Add Rule keyword support Add Rule keyword support Nov 5, 2021
Copy link
Contributor

@ciaranmcnulty ciaranmcnulty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really good that you've used the cucumber tests to guide things - your comment about the Scenario Outline difference is captured in #153

I've left a few comments, the ones marked [BC] would allow us to do this as a minor release, I'm not sure if that's the right approach or not yet

*
* @return string
*/
public function getRuleKeywords();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BC] We should define a new interface that extends KeywordsInterface and adds this method

@@ -72,6 +77,7 @@ public function __construct(
$description,
array $tags,
BackgroundNode $background = null,
array $rules,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BC] we should add this as the last parameter and make it optional (with a default)

@@ -72,6 +77,7 @@ public function __construct(
$description,
array $tags,
BackgroundNode $background = null,
array $rules,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight concern that we lose the ordering of scenarios+rules here by having them as separate arguments. (The main concern is the impact on Behat's formatters).

Perhaps we should be passing an array of Scenarios+Rules? Needs some thought

/**
* @return RuleNode[]
*/
public function getRules(): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BC] We need to consider how a consumer will know this method is available. Maybe we need an interface to hint it? I slightly prefer

if ($featureNode instanceof FeatureRulesNode) {

vs

if(method_exists($featureNode, 'getRules')){

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if a consumer does not want to have to check for existence, the easiest way is to bump their min version of behat/gherkin.

To me, there is no need for an interface (which would not be allowed to be removed without a BC break, and there is no right way to trigger deprecations for instanceof checks relying on deprecated interfaces, only static analysis can do it)

@@ -100,6 +100,7 @@ public function translationTestDataProvider()
,
array(),
$background,
[], // TODO: rules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be resolved before merge

@ciaranmcnulty
Copy link
Contributor

@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
Copy link
Contributor Author

unkind commented Nov 10, 2021

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
Copy link
Contributor Author

unkind commented Feb 8, 2022

#245 is just better way for this.

@unkind unkind closed this Feb 8, 2022
@unkind unkind deleted the feature-rule-keyword branch February 9, 2022 12:52
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.

3 participants