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

Incorrect Given/When/Then behavior (according to Gherkin Reference) #25

Closed
tylerhartwig opened this issue Oct 26, 2018 · 2 comments
Closed

Comments

@tylerhartwig
Copy link

I believe, according to the behavior I am seeing in some of my tests, and in the source code, that step definitions are implemented in a way that is different than the Gherkin definition.

https://docs.cucumber.io/gherkin/reference/#steps

According to the definition the key word (Given, When, or Then) should not be taken into account when initially loading a step definition. However, you should not be allowed to use Given and Then on the same step definition within the same scenario.

I have the case where I've defined a When step definition using the When Attribute, but I am invoking that step definition underneath a Give (using And however). When running with Xunit, I am told that I am missing a step definition.

My setup looks something like the following, for clarity:

Step definition

let [<When>] ``I have defined a step definition`` () = () 
Feature: Test Feature

  Scenario: All initial keywords are fair game 
    Given I am writing a test
      And I have defined a step definition
    When I call it with a different keyword initially
    Then the step definition should succeed

Please let me know if this is not intended functionality, or if it is functioning as intended. This was just unexpected behavior compared to my previous BDD experience.

@michalkovy
Copy link
Contributor

I would call this intended functionality.

TickSpec isn't the only BDD framework which differentiates the step types, e.g. I think SpecFlow does the same. However, SpecFlow has both [<When>], [<Then>], [<Given>] attributes and it also has [<StepDefinition>] attribute which would be closer to what Cucumber does but I didn't see that used much.

We could potentially have such attribute but you can do the same today by writing:

let [<Given; When; Then>] ``I have defined a step definition`` () = ()

Semantically the And and But keywords can be seen just as a replacement for one of Given, When, and Then keywords based on context.

@tylerhartwig
Copy link
Author

Ah, I did not realize I could add Given, When, and Then to the same step definition. That allows me to accomplish what I'm looking for I believe. I've always treated all the keywords as the exact same thing in my mind. Thank you for the help :)

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

2 participants