Skip to content

Commit

Permalink
cucumber#545 replace generic Step with Given/When/Then
Browse files Browse the repository at this point in the history
WIP
- need yet to update the snippets/generation
- tests don't pass
  • Loading branch information
mirogta committed Apr 4, 2023
1 parent bcffb1c commit 2edc956
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 150 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func thereShouldBeRemaining(arg1 int) error {
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Given(`^I eat (\d+)$`, iEat)
ctx.When(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
```

Expand All @@ -158,9 +158,9 @@ func thereShouldBeRemaining(arg1 int) error {
}

func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.When(`^I eat (\d+)$`, iEat)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
```

Expand Down Expand Up @@ -307,9 +307,9 @@ func TestFeatures(t *testing.T) {
}

func InitializeScenario(sc *godog.ScenarioContext) {
sc.Step(`^there are (\d+) godogs$`, thereAreGodogs)
sc.Step(`^I eat (\d+)$`, iEat)
sc.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
sc.Given(`^there are (\d+) godogs$`, thereAreGodogs)
sc.When(`^I eat (\d+)$`, iEat)
sc.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}

```
Expand Down
12 changes: 6 additions & 6 deletions _examples/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {

func InitializeScenario(s *godog.ScenarioContext) {
api := &apiFeature{}
s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
s.When(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Then(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Then(`^the response should match json:$`, api.theResponseShouldMatchJSON)
}
```

Expand Down Expand Up @@ -165,9 +165,9 @@ func InitializeScenario(s *godog.ScenarioContext) {
return ctx, nil
})

s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
s.When(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Then(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Then(`^the response should match json:$`, api.theResponseShouldMatchJSON)
}
```

Expand Down
6 changes: 3 additions & 3 deletions _examples/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
api.resetResponse(sc)
return ctx, nil
})
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.When(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Then(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Then(`^the response should match json:$`, api.theResponseShouldMatchJSON)
}
8 changes: 4 additions & 4 deletions _examples/assert-godogs/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
return ctx, nil
})

ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.When(`^I eat (\d+)$`, iEat)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Then(`^there should be none remaining$`, thereShouldBeNoneRemaining)
}

// assertExpectedAndActual is a helper function to allow the step function to call
Expand Down
8 changes: 4 additions & 4 deletions _examples/custom-formatter/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
return ctx, nil
})

ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^this step is pending$`, thisStepIsPending)
ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.When(`^I eat (\d+)$`, iEat)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Then(`^this step is pending$`, thisStepIsPending)
}
8 changes: 4 additions & 4 deletions _examples/db/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
return ctx, nil
})

ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.Step(`^there are users:$`, api.thereAreUsers)
ctx.When(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Then(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Then(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.Given(`^there are users:$`, api.thereAreUsers)
}
8 changes: 4 additions & 4 deletions _examples/godogs/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
return ctx, nil
})

ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.When(`^I eat (\d+)$`, iEat)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Then(`^there should be none remaining$`, thereShouldBeNoneRemaining)
}
10 changes: 5 additions & 5 deletions features/formatter/pretty.feature
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ Feature: pretty formatter
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^undefined doc string$`, undefinedDocString)
ctx.Step(`^undefined table$`, undefinedTable)
ctx.Given(`^undefined doc string$`, undefinedDocString)
ctx.Given(`^undefined table$`, undefinedTable)
}
"""

Expand Down Expand Up @@ -580,7 +580,7 @@ Feature: pretty formatter
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a when step$`, aWhenStep)
ctx.Given(`^a when step$`, aWhenStep)
}
"""

Expand Down Expand Up @@ -615,7 +615,7 @@ Feature: pretty formatter
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a then step$`, aThenStep)
ctx.When(`^a then step$`, aThenStep)
}
"""

Expand Down Expand Up @@ -650,7 +650,7 @@ Feature: pretty formatter
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a given step$`, aGivenStep)
ctx.Then(`^a given step$`, aGivenStep)
}
"""

Expand Down
22 changes: 11 additions & 11 deletions features/snippets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Feature: undefined step snippets
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo)
ctx.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
ctx.When(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo)
ctx.Then(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
}
"""

Expand Down Expand Up @@ -65,9 +65,9 @@ Feature: undefined step snippets
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith)
ctx.Step(`^the response body should be:$`, theResponseBodyShouldBe)
ctx.Step(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe)
ctx.When(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith)
ctx.Then(`^the response body should be:$`, theResponseBodyShouldBe)
ctx.Then(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe)
}
"""

Expand Down Expand Up @@ -97,8 +97,8 @@ Feature: undefined step snippets
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I pull from github\.com$`, iPullFromGithubcom)
ctx.Step(`^the project should be there$`, theProjectShouldBeThere)
ctx.When(`^I pull from github\.com$`, iPullFromGithubcom)
ctx.Then(`^the project should be there$`, theProjectShouldBeThere)
}
"""

Expand All @@ -123,8 +123,8 @@ Feature: undefined step snippets
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket)
ctx.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts)
ctx.Given(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket)
ctx.When(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts)
}
"""

Expand All @@ -149,7 +149,7 @@ Feature: undefined step snippets
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^(\d+) godogs$`, godogs)
ctx.Step(`^"([^"]*)", which costs £(\d+)$`, whichCosts)
ctx.Given(`^(\d+) godogs$`, godogs)
ctx.Given(`^"([^"]*)", which costs £(\d+)$`, whichCosts)
}
"""
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down
12 changes: 6 additions & 6 deletions internal/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func thereShouldBeRemaining(remaining int) error {
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step("^there are (\\d+) godogs$", thereAreGodogs)
ctx.Step("^I eat (\\d+)$", iEat)
ctx.Step("^there should be (\\d+) remaining$", thereShouldBeRemaining)
ctx.Given("^there are (\\d+) godogs$", thereAreGodogs)
ctx.When("^I eat (\\d+)$", iEat)
ctx.Then("^there should be (\\d+) remaining$", thereShouldBeRemaining)
ctx.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario
Expand Down Expand Up @@ -117,9 +117,9 @@ func thereShouldBeRemaining(remaining int) error {
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step("^there are (\\d+) godogs$", thereAreGodogs)
ctx.Step("^I eat (\\d+)$", iEat)
ctx.Step("^there should be (\\d+) remaining$", thereShouldBeRemaining)
ctx.Given("^there are (\\d+) godogs$", thereAreGodogs)
ctx.When("^I eat (\\d+)$", iEat)
ctx.Then("^there should be (\\d+) remaining$", thereShouldBeRemaining)
ctx.BeforeScenario(func(*godog.Scenario) {
godogs.Godogs = 0 // clean the state before every scenario
Expand Down
43 changes: 22 additions & 21 deletions run_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package godog

import (
"bytes"
"github.com/cucumber/messages/go/v21"
"strings"
"testing"

"github.com/cucumber/gherkin/go/v26"
messages "github.com/cucumber/messages/go/v21"

gherkin "github.com/cucumber/gherkin/go/v26"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -40,8 +41,8 @@ func Test_ProgressFormatterWhenStepPanics(t *testing.T) {
fmt: formatters.ProgressFormatterFunc("progress", w),
features: []*models.Feature{&ft},
scenarioInitializer: func(ctx *ScenarioContext) {
ctx.Step(`^one$`, func() error { return nil })
ctx.Step(`^two$`, func() error { panic("omg") })
ctx.When(`^one$`, func() error { return nil })
ctx.Then(`^two$`, func() error { panic("omg") })
},
}

Expand Down Expand Up @@ -74,11 +75,11 @@ func Test_ProgressFormatterWithPanicInMultistep(t *testing.T) {
fmt: formatters.ProgressFormatterFunc("progress", w),
features: []*models.Feature{&ft},
scenarioInitializer: func(ctx *ScenarioContext) {
ctx.Step(`^sub1$`, func() error { return nil })
ctx.Step(`^sub-sub$`, func() error { return nil })
ctx.Step(`^sub2$`, func() []string { return []string{"sub-sub", "sub1", "one"} })
ctx.Step(`^one$`, func() error { return nil })
ctx.Step(`^two$`, func() []string { return []string{"sub1", "sub2"} })
ctx.When(`^sub1$`, func() error { return nil })
ctx.When(`^sub-sub$`, func() error { return nil })
ctx.When(`^sub2$`, func() []string { return []string{"sub-sub", "sub1", "one"} })
ctx.When(`^one$`, func() error { return nil })
ctx.When(`^two$`, func() []string { return []string{"sub1", "sub2"} })
},
}

Expand Down Expand Up @@ -108,10 +109,10 @@ func Test_ProgressFormatterMultistepTemplates(t *testing.T) {
fmt: formatters.ProgressFormatterFunc("progress", w),
features: []*models.Feature{&ft},
scenarioInitializer: func(ctx *ScenarioContext) {
ctx.Step(`^sub-sub$`, func() error { return nil })
ctx.Step(`^substep$`, func() Steps { return Steps{"sub-sub", `unavailable "John" cost 5`, "one", "three"} })
ctx.Step(`^one$`, func() error { return nil })
ctx.Step(`^(t)wo$`, func(s string) Steps { return Steps{"undef", "substep"} })
ctx.When(`^sub-sub$`, func() error { return nil })
ctx.When(`^substep$`, func() Steps { return Steps{"sub-sub", `unavailable "John" cost 5`, "one", "three"} })
ctx.When(`^one$`, func() error { return nil })
ctx.When(`^(t)wo$`, func(s string) Steps { return Steps{"undef", "substep"} })
},
}

Expand Down Expand Up @@ -146,9 +147,9 @@ func undef() error {
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(` + "`^three$`" + `, three)
ctx.Step(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost)
ctx.Step(` + "`^undef$`" + `, undef)
ctx.When(` + "`^three$`" + `, three)
ctx.When(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost)
ctx.When(` + "`^undef$`" + `, undef)
}
`
Expand Down Expand Up @@ -184,8 +185,8 @@ Feature: basic
fmt: formatters.ProgressFormatterFunc("progress", w),
features: []*models.Feature{&ft},
scenarioInitializer: func(ctx *ScenarioContext) {
ctx.Step(`^one$`, func() error { return nil })
ctx.Step(`^two:$`, func(doc *messages.PickleDocString) Steps { return Steps{"one"} })
ctx.When(`^one$`, func() error { return nil })
ctx.When(`^two:$`, func(doc *messages.PickleDocString) Steps { return Steps{"one"} })
},
}

Expand Down Expand Up @@ -228,9 +229,9 @@ Feature: basic
fmt: formatters.ProgressFormatterFunc("progress", w),
features: []*models.Feature{&ft},
scenarioInitializer: func(ctx *ScenarioContext) {
ctx.Step(`^one$`, func() error { return nil })
ctx.Step(`^two$`, func() Steps { return Steps{subStep} })
ctx.Step(`^three:$`, func(doc *messages.PickleDocString) error { return nil })
ctx.When(`^one$`, func() error { return nil })
ctx.Then(`^two$`, func() Steps { return Steps{subStep} })
ctx.Then(`^three:$`, func(doc *messages.PickleDocString) error { return nil })
},
}

Expand Down

0 comments on commit 2edc956

Please sign in to comment.