-
Notifications
You must be signed in to change notification settings - Fork 19
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
"and" & "but" keywords should not be handled as dedicated entities #32
Comments
Hrm, I think you’re right about the behavior of “and” and “but”. Let me look at the spec and some other implementations over the weekend. If we do implement this feature it’s probably something we would want to approach in the AST where we can enforce an error if there are orphans. |
I've looked at some other implementations and confirmed that CucumberSwift is not following defined and expected behavior with this. I don't want to create a breaking change if I can avoid it so I'm pondering some implementation decisions. I'm thinking of doing this over a few releases, to start we can implement the behavior in your example of Then we'll play with the Then we'll deprecate, but not remove At some point later on in life when V4 needs to be a thing we can just remove it altogether. |
Update on this: CucumberSwift v 3.3.6 adds support for using EXAMPLE GHERKIN: Feature description
Scenario: Description
Given some precondition
And some other precondition EXAMPLE SWIFT: Given("some other precondition") { _, _ in
// executes the "And" condition
} NOTE: By scoped appropriately I mean that this Gherkin will not match Feature description
Scenario: Description
And some other precondition Although because the |
Very nice! 😊 |
Background:
The gherkin keywords „And“ and „But“ are just like a placeholder to connect multiple main keywords (eg „Given“, „When“ and „Then“) together in a human-readable sentence.
For example, if you want to combine three given steps like this:
To make it more readable, it makes more sense to combine the phrases with "And", like:
Thus, in my opinion, „And“ is not a dedicated keyword, it's more like a replacement for a main keyword. I think this matches with the cucumber documentation and concept. See more here https://cucumber.io/docs/gherkin/reference/#and-but
Issue:
In CucumberSwift, the „And“ keyword is handled as an own entity, it's not used as a replacement for the keyword used in one of the previous steps. For example, given this code :
This gherkin syntax would be totally fine and the „test“ step would be executed in every 'and' phrase:
Another problem occurs when defining a 'Given' step and you want it to be used for 'And' steps:
This does not work, but in my opinion, it should. Sure, you can find workarounds like
But then you would still face the first problem and your 'Given' step could be used for other keywords which might not be intented.
Suggestion:
When you parse the feature file and combine it with the matching step implementation (
attachClosureToSteps
) you need to check for the „and“ & „but“ keywords, and in that case search for the most-recently parsed main keyword, evaluating a match based on that. Something like that:This specific solution would have at least one problem. Scenario bounds will be ignored. So if you start a scenario with an 'And', it will still be valid:
You could probably see this as a gherkin syntax fault and not make it a responsibility of CucumberSwift to handle these edge cases. But im sure there's a fix for this somewhere around...
What do you think about the problem / solution? If you think it's a solution worth to invest in I might be able to find some time in the future to create a PR.
The text was updated successfully, but these errors were encountered: