Skip to content

Commit

Permalink
Update tests and examples with up to date API (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogarfe authored Feb 18, 2022
1 parent c95871f commit 5efecba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 5 additions & 1 deletion _examples/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Now we can implemented steps, since we know what behavior we expect:
package main

import (
"context"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions _examples/api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion _examples/assert-godogs/godogs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion _examples/db/api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"database/sql"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion _examples/godogs/godogs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5efecba

Please sign in to comment.