Skip to content

Commit

Permalink
Readded some legacy doc for FeatureContext
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnblad committed May 23, 2020
1 parent b0f295d commit 3447519
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func thereShouldBeRemaining(remaining int) error {
return nil
}

func ScenarioContext(s *godog.ScenarioContext) {
// godog v0.9.0 (latest) and earlier
func FeatureContext(s *godog.Suite) {
s.BeforeSuite(func() { Godogs = 0 })

s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
Expand All @@ -191,6 +194,21 @@ func ScenarioContext(s *godog.ScenarioContext) {
Godogs = 0 // clean the state before every scenario
})
}

// godog v0.10.0 (coming release)
func InitiateTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { Godogs = 0 })
}

func InitiateScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)

ctx.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario
})
}
```

Now when you run the `godog` again, you should see:
Expand Down Expand Up @@ -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: InitiateTestSuite,
ScenarioInitializer: InitiateScenario,
Options: &opts,
}.Run()

Expand Down Expand Up @@ -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: InitiateTestSuite,
ScenarioInitializer: InitiateScenario,
Options: &opts,
}.Run()

if st := m.Run(); st > status {
Expand Down Expand Up @@ -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: InitiateTestSuite,
ScenarioInitializer: InitiateScenario,
Options: &opts,
}.Run()

if st := m.Run(); st > status {
Expand Down
4 changes: 2 additions & 2 deletions _examples/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
return godog.ErrPending
}

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

func ScenarioContext(s *godog.ScenarioContext) {
func InitiateScenario(s *godog.ScenarioContext) {
api := &apiFeature{}

s.BeforeScenario(api.resetResponse)
Expand Down
2 changes: 1 addition & 1 deletion _examples/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err erro
return nil
}

func ScenarioContext(s *godog.ScenarioContext) {
func InitiateScenario(s *godog.ScenarioContext) {
api := &apiFeature{}

s.BeforeScenario(api.resetResponse)
Expand Down
4 changes: 2 additions & 2 deletions _examples/assert-godogs/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestMain(m *testing.M) {

status := godog.TestSuite{
Name: "godogs",
ScenarioInitializer: ScenarioContext,
ScenarioInitializer: InitiateScenario,
Options: &opts,
}.Run()

Expand Down Expand Up @@ -65,7 +65,7 @@ func thereShouldBeNoneRemaining() error {
)
}

func ScenarioContext(s *godog.ScenarioContext) {
func InitiateScenario(s *godog.ScenarioContext) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
Expand Down
2 changes: 1 addition & 1 deletion _examples/db/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (a *apiFeature) thereAreUsers(users *godog.Table) error {
return nil
}

func ScenarioContext(s *godog.ScenarioContext) {
func InitiateScenario(s *godog.ScenarioContext) {
api := &apiFeature{}

s.BeforeScenario(api.resetResponse)
Expand Down
21 changes: 13 additions & 8 deletions _examples/godogs/godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: InitiateTestSuite,
ScenarioInitializer: InitiateScenario,
Options: &opts,
}.Run()

if st := m.Run(); st > status {
Expand Down Expand Up @@ -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 InitiateTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { Godogs = 0 })
}

func InitiateScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)

s.BeforeScenario(func(*godog.Scenario) {
ctx.BeforeScenario(func(*godog.Scenario) {
Godogs = 0 // clean the state before every scenario
})
}

0 comments on commit 3447519

Please # to comment.