Update tests and examples with up to date API (#460)

Этот коммит содержится в:
Ricardo García Fernández 2022-02-18 18:26:17 +01:00 коммит произвёл GitHub
родитель c95871f3ce
коммит 5efecbaf10
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -13,6 +13,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
### Changed ### 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]) - 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] ## [v0.12.4]

Просмотреть файл

@ -91,6 +91,7 @@ Now we can implemented steps, since we know what behavior we expect:
package main package main
import ( import (
"context"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -159,7 +160,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
func InitializeScenario(s *godog.ScenarioContext) { func InitializeScenario(s *godog.ScenarioContext) {
api := &apiFeature{} 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(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)

Просмотреть файл

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -73,8 +74,10 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro
func InitializeScenario(ctx *godog.ScenarioContext) { func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{} 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(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON) ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)

Просмотреть файл

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"testing" "testing"
@ -63,8 +64,9 @@ func thereShouldBeNoneRemaining() error {
} }
func InitializeScenario(ctx *godog.ScenarioContext) { 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 Godogs = 0 // clean the state before every scenario
return ctx, nil
}) })
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)

Просмотреть файл

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
@ -125,7 +126,10 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error {
func InitializeScenario(ctx *godog.ScenarioContext) { func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{} 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(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)

Просмотреть файл

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"testing" "testing"
@ -55,8 +56,9 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
} }
func InitializeScenario(ctx *godog.ScenarioContext) { 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 Godogs = 0 // clean the state before every scenario
return ctx, nil
}) })
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)