From 7014a10e2f3ef38c7b2bc87b201b72dc8852ba23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Wed, 14 Oct 2020 08:39:14 +0200 Subject: [PATCH] Fixed the undefined step definitions help (#350) --- README.md | 16 +++++----- _examples/assert-godogs/godogs_test.go | 2 +- _examples/godogs/godogs_test.go | 2 +- features/formatter/pretty.feature | 4 +-- features/snippets.feature | 30 +++++++++---------- flags_deprecated.go | 3 +- internal/builder/builder.go | 3 +- .../events/some_scenarions_including_failing | 2 +- .../pretty/some_scenarions_including_failing | 4 +-- .../some_scenarions_including_failing | 4 +-- internal/formatters/undefined_snippets_gen.go | 4 +-- run_progress_test.go | 8 ++--- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 3e8bfe1..1c4b494 100644 --- a/README.md +++ b/README.md @@ -138,10 +138,10 @@ func thereShouldBeRemaining(arg1 int) error { return godog.ErrPending } -func FeatureContext(s *godog.Suite) { - s.Step(`^I eat (\d+)$`, iEat) - s.Step(`^there are (\d+) godogs$`, thereAreGodogs) - s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I eat (\d+)$`, iEat) + ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) + ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) } ``` @@ -163,10 +163,10 @@ func thereShouldBeRemaining(arg1 int) error { return godog.ErrPending } -func FeatureContext(s *godog.Suite) { - s.Step(`^I eat (\d+)$`, iEat) - s.Step(`^there are (\d+) godogs$`, thereAreGodogs) - s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I eat (\d+)$`, iEat) + ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs) + ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) } ``` diff --git a/_examples/assert-godogs/godogs_test.go b/_examples/assert-godogs/godogs_test.go index e974bfe..ea12883 100644 --- a/_examples/assert-godogs/godogs_test.go +++ b/_examples/assert-godogs/godogs_test.go @@ -14,7 +14,7 @@ import ( var opts = godog.Options{Output: colors.Colored(os.Stdout)} func init() { - godog.BindCommandLineFlags("godog.", &opts) + godog.BindFlags("godog.", flag.CommandLine, &opts) } func TestMain(m *testing.M) { diff --git a/_examples/godogs/godogs_test.go b/_examples/godogs/godogs_test.go index 90272b7..b78e49e 100644 --- a/_examples/godogs/godogs_test.go +++ b/_examples/godogs/godogs_test.go @@ -13,7 +13,7 @@ import ( var opts = godog.Options{Output: colors.Colored(os.Stdout)} func init() { - godog.BindCommandLineFlags("godog.", &opts) + godog.BindFlags("godog.", flag.CommandLine, &opts) } func TestMain(m *testing.M) { diff --git a/features/formatter/pretty.feature b/features/formatter/pretty.feature index 1de2977..82d35b4 100644 --- a/features/formatter/pretty.feature +++ b/features/formatter/pretty.feature @@ -287,8 +287,8 @@ Feature: pretty formatter return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^undefined$`, undefined) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^undefined$`, undefined) } """ diff --git a/features/snippets.feature b/features/snippets.feature index 4550c05..5e507f8 100644 --- a/features/snippets.feature +++ b/features/snippets.feature @@ -28,9 +28,9 @@ Feature: undefined step snippets return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo) - s.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo) + ctx.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe) } """ @@ -56,9 +56,9 @@ Feature: undefined step snippets return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith) - s.Step(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith) + ctx.Step(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe) } """ @@ -87,9 +87,9 @@ Feature: undefined step snippets return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^I pull from github\.com$`, iPullFromGithubcom) - s.Step(`^the project should be there$`, theProjectShouldBeThere) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I pull from github\.com$`, iPullFromGithubcom) + ctx.Step(`^the project should be there$`, theProjectShouldBeThere) } """ @@ -113,9 +113,9 @@ Feature: undefined step snippets return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket) - s.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket) + ctx.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts) } """ @@ -139,8 +139,8 @@ Feature: undefined step snippets return godog.ErrPending } - func FeatureContext(s *godog.Suite) { - s.Step(`^(\d+) godogs$`, godogs) - s.Step(`^"([^"]*)", which costs £(\d+)$`, whichCosts) + func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^(\d+) godogs$`, godogs) + ctx.Step(`^"([^"]*)", which costs £(\d+)$`, whichCosts) } """ diff --git a/flags_deprecated.go b/flags_deprecated.go index 7fb0b78..b7b0f2b 100644 --- a/flags_deprecated.go +++ b/flags_deprecated.go @@ -49,7 +49,8 @@ func FlagSet(opt *Options) *flag.FlagSet { // BindFlags binds godog flags to given flag set prefixed // by given prefix, without overriding usage // -// Deprecated: Use BindCommandLineFlags(prefix, &opts) instead of BindFlags(prefix, flag.CommandLine, &opts) +// Deprecated: Use BindCommandLineFlags(prefix, &opts) +// instead of BindFlags(prefix, flag.CommandLine, &opts) func BindFlags(prefix string, set *flag.FlagSet, opt *Options) { descFormatOption := "How to format tests output. Built-in formats:\n" // @TODO: sort by name diff --git a/internal/builder/builder.go b/internal/builder/builder.go index 69c742e..626e7bb 100644 --- a/internal/builder/builder.go +++ b/internal/builder/builder.go @@ -43,7 +43,6 @@ func init() { {{end}} func main() { - {{if or .TestSuiteContexts .ScenarioContexts .XTestSuiteContexts .XScenarioContexts}} status := godog.TestSuite{ Name: "{{ .Name }}", TestSuiteInitializer: func (ctx *godog.TestSuiteContext) { @@ -64,7 +63,7 @@ func main() { {{end}} }, }.Run() - {{end}} + os.Exit(status) }`)) diff --git a/internal/formatters/formatter-tests/events/some_scenarions_including_failing b/internal/formatters/formatter-tests/events/some_scenarions_including_failing index d220e14..53606be 100644 --- a/internal/formatters/formatter-tests/events/some_scenarions_including_failing +++ b/internal/formatters/formatter-tests/events/some_scenarions_including_failing @@ -26,4 +26,4 @@ {"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:14","timestamp":-6795364578871} {"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:14","timestamp":-6795364578871,"status":"skipped"} {"event":"TestCaseFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:12","timestamp":-6795364578871,"status":"undefined"} -{"event":"TestRunFinished","status":"failed","timestamp":-6795364578871,"snippets":"You can implement step definitions for undefined steps with these snippets:\n\nfunc undefined() error {\n\treturn godog.ErrPending\n}\n\nfunc FeatureContext(s *godog.Suite) {\n\ts.Step(`^undefined$`, undefined)\n}\n","memory":""} +{"event":"TestRunFinished","status":"failed","timestamp":-6795364578871,"snippets":"You can implement step definitions for undefined steps with these snippets:\n\nfunc undefined() error {\n\treturn godog.ErrPending\n}\n\nfunc InitializeScenario(ctx *godog.ScenarioContext) {\n\tctx.Step(`^undefined$`, undefined)\n}\n","memory":""} diff --git a/internal/formatters/formatter-tests/pretty/some_scenarions_including_failing b/internal/formatters/formatter-tests/pretty/some_scenarions_including_failing index cbd7f83..016f09a 100644 --- a/internal/formatters/formatter-tests/pretty/some_scenarions_including_failing +++ b/internal/formatters/formatter-tests/pretty/some_scenarions_including_failing @@ -32,7 +32,7 @@ func undefined() error { return godog.ErrPending } -func FeatureContext(s *godog.Suite) { - s.Step(`^undefined$`, undefined) +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^undefined$`, undefined) } diff --git a/internal/formatters/formatter-tests/progress/some_scenarions_including_failing b/internal/formatters/formatter-tests/progress/some_scenarions_including_failing index 67e0099..43146df 100644 --- a/internal/formatters/formatter-tests/progress/some_scenarions_including_failing +++ b/internal/formatters/formatter-tests/progress/some_scenarions_including_failing @@ -18,7 +18,7 @@ func undefined() error { return godog.ErrPending } -func FeatureContext(s *godog.Suite) { - s.Step(`^undefined$`, undefined) +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(`^undefined$`, undefined) } diff --git a/internal/formatters/undefined_snippets_gen.go b/internal/formatters/undefined_snippets_gen.go index b61dfd3..d47f3bc 100644 --- a/internal/formatters/undefined_snippets_gen.go +++ b/internal/formatters/undefined_snippets_gen.go @@ -27,8 +27,8 @@ var undefinedSnippetsTpl = template.Must(template.New("snippets").Funcs(snippetH return godog.ErrPending } -{{end}}func FeatureContext(s *godog.Suite) { {{ range . }} - s.Step({{ backticked .Expr }}, {{ .Method }}){{end}} +{{end}}func InitializeScenario(ctx *godog.ScenarioContext) { {{ range . }} + ctx.Step({{ backticked .Expr }}, {{ .Method }}){{end}} } `)) diff --git a/run_progress_test.go b/run_progress_test.go index 2095b80..5f67db5 100644 --- a/run_progress_test.go +++ b/run_progress_test.go @@ -145,10 +145,10 @@ func undef() error { return godog.ErrPending } -func FeatureContext(s *godog.Suite) { - s.Step(` + "`^three$`" + `, three) - s.Step(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost) - s.Step(` + "`^undef$`" + `, undef) +func InitializeScenario(ctx *godog.ScenarioContext) { + ctx.Step(` + "`^three$`" + `, three) + ctx.Step(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost) + ctx.Step(` + "`^undef$`" + `, undef) } `