Comments (14)
I'm keen to start working on this. Just checking that no one has started already
from godog.
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.
That makes sense to me!
from godog.
@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.
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.
Looking at
Line 261 in bcffb1c
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.
@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.
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.
@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.
That's more or less what I was planning to do as well, is there anything else you were looking to do?
from godog.
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.
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.
@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 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)
- Add support for cucumber expressions HOT 5
- screen shot in _examples/api is now wrong HOT 4
- Support for Go 1.20
- runAfterScenarioHooks invoke twice when step failed that is not the last step HOT 4
- Enhancement to allow to skip a test from the code HOT 8
- Background Outline HOT 2
- Setting option `Concurrency = 2` fails when running the Example HOT 1
- click on run tests but tests are not running HOT 1
- Please update the concurrency paragraph in the docs to clarify if scenario outlines run in parallel or only the scenarios HOT 1
- Is this feature file in godog/_examples/godogs running sequencially ? HOT 2
- Why Getting total scenarios as 6 while I am having total 5 scenarios HOT 3
- Skipping a test by returning `godog.ErrSkip` does not work? HOT 4
- print error stack when panic
- step function support return a nil Context with error HOT 1
- Conflict between global flags set by godog.BindCommandLineFlags and spf13/cobra HOT 1
- HELP: I want to know the index of a scenario in a scenario outline in the before scenario hook.
- Can't navigate to step definition from Gherkin step
- Unexpected step line values in cucumber report generated by Godog for scenario outlines
- ReadMe add step `go get ...` see provided patch to fix it
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godog.