fsprojects / TickSpec

Lean .NET BDD framework with powerful F# integration
Apache License 2.0
133 stars 23 forks source link

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

Closed tylerhartwig closed 5 years ago

tylerhartwig commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 :)