From c6537d64533aa74ae0fc4c55e8691b6f4a0cb035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Fri, 18 Feb 2022 13:41:04 +0100 Subject: [PATCH 1/2] #459 - tests remove deprecated methods --- _examples/api/README.md | 6 +++++- _examples/api/api_test.go | 7 +++++-- _examples/assert-godogs/godogs_test.go | 4 +++- _examples/db/api_test.go | 6 +++++- _examples/godogs/godogs_test.go | 4 +++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/_examples/api/README.md b/_examples/api/README.md index d4781eee..e1a04e3a 100644 --- a/_examples/api/README.md +++ b/_examples/api/README.md @@ -91,6 +91,7 @@ Now we can implemented steps, since we know what behavior we expect: package main import ( + "context" "bytes" "encoding/json" "fmt" @@ -159,7 +160,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error { func InitializeScenario(s *godog.ScenarioContext) { api := &apiFeature{} - s.BeforeScenario(api.resetResponse) + ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { + api.resetResponse(sc) + 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) diff --git a/_examples/api/api_test.go b/_examples/api/api_test.go index 19bce640..8f18a714 100644 --- a/_examples/api/api_test.go +++ b/_examples/api/api_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "net/http" @@ -73,8 +74,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro func InitializeScenario(ctx *godog.ScenarioContext) { api := &apiFeature{} - ctx.BeforeScenario(api.resetResponse) - + ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { + 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) diff --git a/_examples/assert-godogs/godogs_test.go b/_examples/assert-godogs/godogs_test.go index f48b04c0..180339c8 100644 --- a/_examples/assert-godogs/godogs_test.go +++ b/_examples/assert-godogs/godogs_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "os" "testing" @@ -63,8 +64,9 @@ func thereShouldBeNoneRemaining() error { } func InitializeScenario(ctx *godog.ScenarioContext) { - ctx.BeforeScenario(func(*godog.Scenario) { + ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { Godogs = 0 // clean the state before every scenario + return ctx, nil }) ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) diff --git a/_examples/db/api_test.go b/_examples/db/api_test.go index 202e9b3b..4098525e 100644 --- a/_examples/db/api_test.go +++ b/_examples/db/api_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "database/sql" "encoding/json" "fmt" @@ -125,7 +126,10 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error { func InitializeScenario(ctx *godog.ScenarioContext) { api := &apiFeature{} - ctx.BeforeScenario(api.resetResponse) + ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { + 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) diff --git a/_examples/godogs/godogs_test.go b/_examples/godogs/godogs_test.go index 1aaffb82..f458c5ad 100644 --- a/_examples/godogs/godogs_test.go +++ b/_examples/godogs/godogs_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "os" "testing" @@ -55,8 +56,9 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) { } func InitializeScenario(ctx *godog.ScenarioContext) { - ctx.BeforeScenario(func(*godog.Scenario) { + ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { Godogs = 0 // clean the state before every scenario + return ctx, nil }) ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) From 30a9d41314bc8ea8b2cdaf42f67c88e75f809fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Garc=C3=ADa=20Fern=C3=A1ndez?= Date: Fri, 18 Feb 2022 14:12:47 +0100 Subject: [PATCH 2/2] #459 - update changelog unreleased --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6348fa4f..aacf4955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ### Changed - Changed underlying cobra command setup to return errors instead of calling `os.Exit` directly to enable simpler testing. ([454](https://github.com/cucumber/godog/pull/454) - [mxygem]) +- Remove use of deprecated methods from `_examples`. ([460](https://github.com/cucumber/godog/pull/460) - [ricardogarfe]) ## [v0.12.4]