Merge pull request #297 from cucumber/context-docs

Readded some legacy doc for FeatureContext
Этот коммит содержится в:
Fredrik Lönnblad 2020-05-23 09:02:20 +02:00 коммит произвёл GitHub
родитель b0f295dc28 13acd2d219
коммит 43844be3e9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 82 добавлений и 38 удалений

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

@ -182,14 +182,32 @@ func thereShouldBeRemaining(remaining int) error {
return nil
}
func ScenarioContext(s *godog.ScenarioContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
// godog v0.9.0 (latest) and earlier
func FeatureContext(s *godog.Suite) {
s.BeforeSuite(func() { Godogs = 0 })
s.BeforeScenario(func(*godog.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()
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{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
@ -294,10 +319,17 @@ func TestMain(m *testing.M) {
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{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
Options: opts,
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
if st := m.Run(); st > status {
@ -326,10 +358,17 @@ func TestMain(m *testing.M) {
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{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
Options: opts,
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
if st := m.Run(); st > status {

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

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

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

@ -70,12 +70,12 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro
return nil
}
func ScenarioContext(s *godog.ScenarioContext) {
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{}
s.BeforeScenario(api.resetResponse)
ctx.BeforeScenario(api.resetResponse)
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 should match json:$`, api.theResponseShouldMatchJSON)
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)
}

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

@ -23,7 +23,7 @@ func TestMain(m *testing.M) {
status := godog.TestSuite{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
@ -65,15 +65,15 @@ func thereShouldBeNoneRemaining() error {
)
}
func ScenarioContext(s *godog.ScenarioContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
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) {
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)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
}
// 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
}
func ScenarioContext(s *godog.ScenarioContext) {
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{}
s.BeforeScenario(api.resetResponse)
ctx.BeforeScenario(api.resetResponse)
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 should match json:$`, api.theResponseShouldMatchJSON)
s.Step(`^there are users:$`, api.thereAreUsers)
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)
ctx.Step(`^there are users:$`, api.thereAreUsers)
}

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

@ -21,9 +21,10 @@ func TestMain(m *testing.M) {
opts.Paths = flag.Args()
status := godog.TestSuite{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
Options: &opts,
Name: "godogs",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
if st := m.Run(); st > status {
@ -52,12 +53,16 @@ func thereShouldBeRemaining(remaining int) error {
return nil
}
func ScenarioContext(s *godog.ScenarioContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { Godogs = 0 })
}
s.BeforeScenario(func(*godog.Scenario) {
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)
}