Readded some legacy doc for FeatureContext

Этот коммит содержится в:
Fredrik Lönnblad 2020-05-23 08:36:55 +02:00
родитель b0f295dc28
коммит 13acd2d219
6 изменённых файлов: 82 добавлений и 38 удалений

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

@ -182,14 +182,32 @@ func thereShouldBeRemaining(remaining int) error {
return nil return nil
} }
func ScenarioContext(s *godog.ScenarioContext) { // godog v0.9.0 (latest) and earlier
s.Step(`^there are (\d+) godogs$`, thereAreGodogs) func FeatureContext(s *godog.Suite) {
s.Step(`^I eat (\d+)$`, iEat) s.BeforeSuite(func() { Godogs = 0 })
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
s.BeforeScenario(func(*godog.Scenario) { s.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario Godogs = 0 // clean the state before every scenario
}) })
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
// godog v0.10.0 (coming release)
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { Godogs = 0 })
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario
})
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
} }
``` ```
@ -262,9 +280,16 @@ func TestMain(m *testing.M) {
flag.Parse() flag.Parse()
opts.Paths = flag.Args() 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{ status := godog.TestSuite{
Name: "godogs", Name: "godogs",
ScenarioInitializer: ScenarioContext, TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts, Options: &opts,
}.Run() }.Run()
@ -294,10 +319,17 @@ func TestMain(m *testing.M) {
Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order 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{ status := godog.TestSuite{
Name: "godogs", Name: "godogs",
ScenarioInitializer: ScenarioContext, TestSuiteInitializer: InitializeTestSuite,
Options: opts, ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run() }.Run()
if st := m.Run(); st > status { if st := m.Run(); st > status {
@ -326,10 +358,17 @@ func TestMain(m *testing.M) {
Paths: []string{"features"}, 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{ status := godog.TestSuite{
Name: "godogs", Name: "godogs",
ScenarioInitializer: ScenarioContext, TestSuiteInitializer: InitializeTestSuite,
Options: opts, ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run() }.Run()
if st := m.Run(); st > status { if st := m.Run(); st > status {

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

@ -74,7 +74,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
return godog.ErrPending return godog.ErrPending
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeScenario(s *godog.ScenarioContext) {
api := &apiFeature{} api := &apiFeature{}
s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo) s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
@ -156,7 +156,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
return return
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeScenario(s *godog.ScenarioContext) {
api := &apiFeature{} api := &apiFeature{}
s.BeforeScenario(api.resetResponse) s.BeforeScenario(api.resetResponse)

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

@ -70,12 +70,12 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro
return nil return nil
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{} api := &apiFeature{}
s.BeforeScenario(api.resetResponse) ctx.BeforeScenario(api.resetResponse)
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo) ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON) ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
} }

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

@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
status := godog.TestSuite{ status := godog.TestSuite{
Name: "godogs", Name: "godogs",
ScenarioInitializer: ScenarioContext, ScenarioInitializer: InitializeScenario,
Options: &opts, Options: &opts,
}.Run() }.Run()
@ -65,15 +65,15 @@ func thereShouldBeNoneRemaining() error {
) )
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeScenario(ctx *godog.ScenarioContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs) ctx.BeforeScenario(func(*godog.Scenario) {
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
s.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
s.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario Godogs = 0 // clean the state before every scenario
}) })
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
} }
// assertExpectedAndActual is a helper function to allow the step function to call // assertExpectedAndActual is a helper function to allow the step function to call

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

@ -122,13 +122,13 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error {
return nil return nil
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{} api := &apiFeature{}
s.BeforeScenario(api.resetResponse) ctx.BeforeScenario(api.resetResponse)
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo) ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe) ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON) ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
s.Step(`^there are users:$`, api.thereAreUsers) ctx.Step(`^there are users:$`, api.thereAreUsers)
} }

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

@ -22,7 +22,8 @@ func TestMain(m *testing.M) {
status := godog.TestSuite{ status := godog.TestSuite{
Name: "godogs", Name: "godogs",
ScenarioInitializer: ScenarioContext, TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts, Options: &opts,
}.Run() }.Run()
@ -52,12 +53,16 @@ func thereShouldBeRemaining(remaining int) error {
return nil return nil
} }
func ScenarioContext(s *godog.ScenarioContext) { func InitializeTestSuite(ctx *godog.TestSuiteContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs) ctx.BeforeSuite(func() { Godogs = 0 })
s.Step(`^I eat (\d+)$`, iEat) }
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
s.BeforeScenario(func(*godog.Scenario) { func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario Godogs = 0 // clean the state before every scenario
}) })
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
} }