From 34475191e3008c5fd89827001f29ddff63b10a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Sat, 23 May 2020 08:36:55 +0200 Subject: [PATCH] Readded some legacy doc for FeatureContext --- README.md | 51 +++++++++++++++++++++++--- _examples/api/README.md | 4 +- _examples/api/api_test.go | 2 +- _examples/assert-godogs/godogs_test.go | 4 +- _examples/db/api_test.go | 2 +- _examples/godogs/godogs_test.go | 21 +++++++---- 6 files changed, 64 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8d6a6ce7..63bd81e2 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,10 @@ func thereShouldBeRemaining(remaining int) error { return nil } -func ScenarioContext(s *godog.ScenarioContext) { +// godog v0.9.0 (latest) and earlier +func FeatureContext(s *godog.Suite) { + s.BeforeSuite(func() { Godogs = 0 }) + s.Step(`^there are (\d+) godogs$`, thereAreGodogs) s.Step(`^I eat (\d+)$`, iEat) s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) @@ -191,6 +194,21 @@ func ScenarioContext(s *godog.ScenarioContext) { Godogs = 0 // clean the state before every scenario }) } + +// godog v0.10.0 (coming release) +func InitiateTestSuite(ctx *godog.TestSuiteContext) { + ctx.BeforeSuite(func() { Godogs = 0 }) +} + +func InitiateScenario(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.BeforeScenario(func(*godog.Scenario) { + Godogs = 0 // clean the state before every scenario + }) +} ``` Now when you run the `godog` again, you should see: @@ -262,9 +280,16 @@ func TestMain(m *testing.M) { flag.Parse() opts.Paths = flag.Args() + // godog v0.9.0 (latest) and earlier + status := godog.RunWithOptions("godogs", func(s *godog.Suite) { + FeatureContext(s) + }, opts) + + // godog v0.10.0 (coming release) status := godog.TestSuite{ Name: "godogs", - ScenarioInitializer: ScenarioContext, + TestSuiteInitializer: InitiateTestSuite, + ScenarioInitializer: InitiateScenario, Options: &opts, }.Run() @@ -294,10 +319,17 @@ func TestMain(m *testing.M) { Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order } + // godog v0.9.0 (latest) and earlier + status := godog.RunWithOptions("godogs", func(s *godog.Suite) { + FeatureContext(s) + }, opts) + + // godog v0.10.0 (coming release) status := godog.TestSuite{ Name: "godogs", - ScenarioInitializer: ScenarioContext, - Options: opts, + TestSuiteInitializer: InitiateTestSuite, + ScenarioInitializer: InitiateScenario, + Options: &opts, }.Run() if st := m.Run(); st > status { @@ -326,10 +358,17 @@ func TestMain(m *testing.M) { Paths: []string{"features"}, } + // godog v0.9.0 (latest) and earlier + status := godog.RunWithOptions("godogs", func(s *godog.Suite) { + FeatureContext(s) + }, opts) + + // godog v0.10.0 (coming release) status := godog.TestSuite{ Name: "godogs", - ScenarioInitializer: ScenarioContext, - Options: opts, + TestSuiteInitializer: InitiateTestSuite, + ScenarioInitializer: InitiateScenario, + Options: &opts, }.Run() if st := m.Run(); st > status { diff --git a/_examples/api/README.md b/_examples/api/README.md index b5821bf4..4e34bb92 100644 --- a/_examples/api/README.md +++ b/_examples/api/README.md @@ -74,7 +74,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error { return godog.ErrPending } -func ScenarioContext(s *godog.ScenarioContext) { +func InitiateScenario(s *godog.ScenarioContext) { api := &apiFeature{} s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo) s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) @@ -156,7 +156,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error { return } -func ScenarioContext(s *godog.ScenarioContext) { +func InitiateScenario(s *godog.ScenarioContext) { api := &apiFeature{} s.BeforeScenario(api.resetResponse) diff --git a/_examples/api/api_test.go b/_examples/api/api_test.go index 1c292c23..25bde503 100644 --- a/_examples/api/api_test.go +++ b/_examples/api/api_test.go @@ -70,7 +70,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro return nil } -func ScenarioContext(s *godog.ScenarioContext) { +func InitiateScenario(s *godog.ScenarioContext) { api := &apiFeature{} s.BeforeScenario(api.resetResponse) diff --git a/_examples/assert-godogs/godogs_test.go b/_examples/assert-godogs/godogs_test.go index 559aee99..5dc9d474 100644 --- a/_examples/assert-godogs/godogs_test.go +++ b/_examples/assert-godogs/godogs_test.go @@ -23,7 +23,7 @@ func TestMain(m *testing.M) { status := godog.TestSuite{ Name: "godogs", - ScenarioInitializer: ScenarioContext, + ScenarioInitializer: InitiateScenario, Options: &opts, }.Run() @@ -65,7 +65,7 @@ func thereShouldBeNoneRemaining() error { ) } -func ScenarioContext(s *godog.ScenarioContext) { +func InitiateScenario(s *godog.ScenarioContext) { s.Step(`^there are (\d+) godogs$`, thereAreGodogs) s.Step(`^I eat (\d+)$`, iEat) s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) diff --git a/_examples/db/api_test.go b/_examples/db/api_test.go index ec765841..0abd53d3 100644 --- a/_examples/db/api_test.go +++ b/_examples/db/api_test.go @@ -122,7 +122,7 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error { return nil } -func ScenarioContext(s *godog.ScenarioContext) { +func InitiateScenario(s *godog.ScenarioContext) { api := &apiFeature{} s.BeforeScenario(api.resetResponse) diff --git a/_examples/godogs/godogs_test.go b/_examples/godogs/godogs_test.go index 4e5cea57..fdb28311 100644 --- a/_examples/godogs/godogs_test.go +++ b/_examples/godogs/godogs_test.go @@ -21,9 +21,10 @@ func TestMain(m *testing.M) { opts.Paths = flag.Args() status := godog.TestSuite{ - Name: "godogs", - ScenarioInitializer: ScenarioContext, - Options: &opts, + Name: "godogs", + TestSuiteInitializer: InitiateTestSuite, + ScenarioInitializer: InitiateScenario, + Options: &opts, }.Run() if st := m.Run(); st > status { @@ -52,12 +53,16 @@ func thereShouldBeRemaining(remaining int) error { return nil } -func ScenarioContext(s *godog.ScenarioContext) { - s.Step(`^there are (\d+) godogs$`, thereAreGodogs) - s.Step(`^I eat (\d+)$`, iEat) - s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) +func InitiateTestSuite(ctx *godog.TestSuiteContext) { + ctx.BeforeSuite(func() { Godogs = 0 }) +} + +func InitiateScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) + ctx.Step(`^I eat (\d+)$`, iEat) + ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) - s.BeforeScenario(func(*godog.Scenario) { + ctx.BeforeScenario(func(*godog.Scenario) { Godogs = 0 // clean the state before every scenario }) }