Giter Club home page Giter Club logo

Comments (14)

otrava7 avatar otrava7 commented on June 16, 2024 2

I'm keen to start working on this. Just checking that no one has started already

from godog.

otrava7 avatar otrava7 commented on June 16, 2024 1

Hello @mirogta,
One thing to note is we have already introduced Given/When/Then functions as part of: #509
The above is not released yet, but the functions will be available once released. The Step function is not deprecated at this point though.

from godog.

otrava7 avatar otrava7 commented on June 16, 2024 1

That makes sense to me!

from godog.

vearutop avatar vearutop commented on June 16, 2024 1

@seanw2020 Recent changes have not been released as a tagged version yet, however you can go ahead and upgrade to latest main by go get -u github.com/cucumber/godog@main.

from godog.

crosscode-nl avatar crosscode-nl commented on June 16, 2024 1

Hi all, I created a PR that allows us to select a different snippet function for generating missing steps. The two options are now:

  • steps_func
  • gwt_func

steps_func is the default and old behaviour, gwt_func is a new function that generates the steps with the Given/When/Then keywords

I intend to add more snippet functions if this PR is merged.

For example: I personally would like the functions to be prefixed with the given/when/then keyword as well since Go does not use attributes. Also, I often work with methods on a TestFixture struct.

With this PR people can add snippet functions that match their workflow best.

from godog.

mirogta avatar mirogta commented on June 16, 2024

Looking at

func (ctx *ScenarioContext) Given(expr, stepFunc interface{}) {
, there are already funcs Given/When/Then. So we can perhaps mark the "preferred" Step func as obsolete.

Concern about terminology:
The hooks BeforeStep and AfterStep should stay. Assuming these can be explained in the docs, as in Given/When/Then are the actual funcs and Step is just their abstraction.

from godog.

mirogta avatar mirogta commented on June 16, 2024

@otrava7 thanks - yeah, found it as well now.

I'm looking at this more holistically, i.e. can we also replace the generic Step everywhere else, in the snippets, in the documentation & examples etc.

from godog.

seanw2020 avatar seanw2020 commented on June 16, 2024

On a related note, the docs say, at https://github.com/cucumber/godog:

Alternatively, you can also specify the keyword (Given, When, Then...) when creating the step definitions:

But that doesn't work when go.mod says require github.com/cucumber/godog v0.12.6 because you get this instead:

./godogs_test.go:18:6: ctx.Given undefined (type *godog.ScenarioContext has no field or method Given)

from godog.

mirogta avatar mirogta commented on June 16, 2024

@otrava7 that's great! I've started looking into it to understand the scope and effort a bit more, but very happy for someone else to actually deliver it. Hope the (WIP) branch above helps.

from godog.

otrava7 avatar otrava7 commented on June 16, 2024

That's more or less what I was planning to do as well, is there anything else you were looking to do?

from godog.

mirogta avatar mirogta commented on June 16, 2024

That's more or less what I was planning to do as well, is there anything else you were looking to do?

No, that's it.

Observations:

  • There are tests for the Step definition having different meaning: Given/When/Then. Does it actually make sense? That made it a bit difficult to choose which keyword should the Step be replaced with, but I've made the best guesses. Should it even be allowed? E.g. if I have an assert (Then) then how would it make sense to use it in arrangement (Given)?
  • There's a single template for the code snippets for all Given/When/Then - it might need to be split to give more flexibility and potentially allow configuring custom snippets.
  • There's also a single slice for all runtime steps - probably makes sense to keep it and still continue to refer to all Given/When/Then as a Step abstraction.
  • Not for this ticket, but Makefile didn't work OOB for me = more effort to contribute. Can we make it more flexible so it's easier to use with multiple installed versions of Go? It doesn't seem like a good idea to assume everyone has the required Go version, esp. when it's not the latest stable.

from godog.

otrava7 avatar otrava7 commented on June 16, 2024

There are tests for the Step definition having different meaning: Given/When/Then. Does it actually make sense? That made it a bit difficult to choose which keyword should the Step be replaced with, but I've made the best guesses. Should it even be allowed? E.g. if I have an assert (Then) then how would it make sense to use it in arrangement (Given)?

Could you give an example for this? The Given()/When()/Then() functions are built to only match their respective keyword in the feature files. With the Step() function, it could match no matter the keyword.

from godog.

soulcodex avatar soulcodex commented on June 16, 2024

@mirogta One question, Given and When with this approach will match and understand the And too? For example:

Given 2 ducks and one hunter 
And the hunter is ready for the action -> This will still matching regardless Given, When or Then ?
When the hunter shoots one time
Then "1" ducks left alive

from godog.

mirogta avatar mirogta commented on June 16, 2024

@mirogta One question, Given and When with this approach will match and understand the And too? For example:

Given 2 ducks and one hunter 
And the hunter is ready for the action -> This will still matching regardless Given, When or Then ?
When the hunter shoots one time
Then "1" ducks left alive

I'm not sure I understand your question exactly. The line with And should match, but not necessarily "regardless"…

The And is imho used for readability and it needs to know in which context it's used, whether it's a replacement for Given, When or Then. The same example without And should also work:

Given 2 ducks and one hunter 
Given the hunter is ready for the action -> "And" in this context would be a replacement for "Given"
When the hunter shoots one time
Then "1" ducks left alive

But to your point about "regardless", the following should be invalid:

Given 2 ducks and one hunter 
Then the hunter is ready for the action  -> "And" in this context cannot be a replacement for "Then", the Given-When-Then has a strict order
When the hunter shoots one time
Then "1" ducks left alive

from godog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.