Skip to content

Commit 5efecba

Browse files
authored
Update tests and examples with up to date API (#460)
1 parent c95871f commit 5efecba

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
1313
### Changed
1414

1515
- 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])
16+
- Remove use of deprecated methods from `_examples`. ([460](https://github.com/cucumber/godog/pull/460) - [ricardogarfe])
1617

1718
## [v0.12.4]
1819

_examples/api/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Now we can implemented steps, since we know what behavior we expect:
9191
package main
9292

9393
import (
94+
"context"
9495
"bytes"
9596
"encoding/json"
9697
"fmt"
@@ -159,7 +160,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
159160
func InitializeScenario(s *godog.ScenarioContext) {
160161
api := &apiFeature{}
161162

162-
s.BeforeScenario(api.resetResponse)
163+
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
164+
api.resetResponse(sc)
165+
return ctx, nil
166+
})
163167

164168
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
165169
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)

_examples/api/api_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"net/http"
@@ -73,8 +74,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro
7374
func InitializeScenario(ctx *godog.ScenarioContext) {
7475
api := &apiFeature{}
7576

76-
ctx.BeforeScenario(api.resetResponse)
77-
77+
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
78+
api.resetResponse(sc)
79+
return ctx, nil
80+
})
7881
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
7982
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
8083
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)

_examples/assert-godogs/godogs_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"testing"
@@ -63,8 +64,9 @@ func thereShouldBeNoneRemaining() error {
6364
}
6465

6566
func InitializeScenario(ctx *godog.ScenarioContext) {
66-
ctx.BeforeScenario(func(*godog.Scenario) {
67+
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
6768
Godogs = 0 // clean the state before every scenario
69+
return ctx, nil
6870
})
6971

7072
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)

_examples/db/api_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"database/sql"
56
"encoding/json"
67
"fmt"
@@ -125,7 +126,10 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error {
125126
func InitializeScenario(ctx *godog.ScenarioContext) {
126127
api := &apiFeature{}
127128

128-
ctx.BeforeScenario(api.resetResponse)
129+
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
130+
api.resetResponse(sc)
131+
return ctx, nil
132+
})
129133

130134
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
131135
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)

_examples/godogs/godogs_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"testing"
@@ -55,8 +56,9 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
5556
}
5657

5758
func InitializeScenario(ctx *godog.ScenarioContext) {
58-
ctx.BeforeScenario(func(*godog.Scenario) {
59+
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
5960
Godogs = 0 // clean the state before every scenario
61+
return ctx, nil
6062
})
6163

6264
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)

0 commit comments

Comments
 (0)