diff --git a/README.md b/README.md index e068d0d..7771487 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ func thereShouldBeRemaining(remaining int) error { return nil } -func featureContext(s *godog.Suite) { +func FeatureContext(s *godog.Suite) { s.Step(`^there are (\d+) godogs$`, thereAreGodogs) s.Step(`^I eat (\d+)$`, iEat) s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) diff --git a/builder.go b/builder.go index 337a5a7..9fe0a39 100644 --- a/builder.go +++ b/builder.go @@ -12,6 +12,7 @@ import ( "path/filepath" "strings" "text/template" + "unicode" ) var godogImportPath = "github.com/DATA-DOG/godog" @@ -215,5 +216,16 @@ func processPackageTestFiles(packs ...[]string) ([]string, error) { ctxs = append(ctxs, astContexts(node)...) } } + var failed []string + for _, ctx := range ctxs { + runes := []rune(ctx) + if unicode.IsLower(runes[0]) { + expected := append([]rune{unicode.ToUpper(runes[0])}, runes[1:]...) + failed = append(failed, fmt.Sprintf("%s - should be: %s", ctx, string(expected))) + } + } + if len(failed) > 0 { + return ctxs, fmt.Errorf("godog contexts must be exported:\n\t%s", strings.Join(failed, "\n\t")) + } return ctxs, nil } diff --git a/examples/api/api_test.go b/examples/api/api_test.go index ab2af6b..919cfde 100644 --- a/examples/api/api_test.go +++ b/examples/api/api_test.go @@ -67,7 +67,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er return } -func featureContext(s *godog.Suite) { +func FeatureContext(s *godog.Suite) { api := &apiFeature{} s.BeforeScenario(api.resetResponse) diff --git a/examples/db/api_test.go b/examples/db/api_test.go index ef48102..76ab7b1 100644 --- a/examples/db/api_test.go +++ b/examples/db/api_test.go @@ -8,7 +8,6 @@ import ( "net/http/httptest" "strings" - "github.com/DATA-DOG/go-txdb" "github.com/DATA-DOG/godog" "github.com/DATA-DOG/godog/gherkin" ) @@ -118,7 +117,7 @@ func (a *apiFeature) thereAreUsers(users *gherkin.DataTable) error { return nil } -func featureContext(s *godog.Suite) { +func FeatureContext(s *godog.Suite) { api := &apiFeature{} s.BeforeScenario(api.resetResponse) diff --git a/examples/godogs/godog_test.go b/examples/godogs/godog_test.go index b94f2dc..343cf91 100644 --- a/examples/godogs/godog_test.go +++ b/examples/godogs/godog_test.go @@ -26,7 +26,7 @@ func thereShouldBeRemaining(remaining int) error { return nil } -func featureContext(s *godog.Suite) { +func FeatureContext(s *godog.Suite) { s.Step(`^there are (\d+) godogs$`, thereAreGodogs) s.Step(`^I eat (\d+)$`, iEat) s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) diff --git a/features/snippets.feature b/features/snippets.feature index f95058d..af1a9e0 100644 --- a/features/snippets.feature +++ b/features/snippets.feature @@ -28,7 +28,7 @@ Feature: undefined step snippets return godog.ErrPending } - func featureContext(s *godog.Suite) { + func FeatureContext(s *godog.Suite) { s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo) s.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe) } @@ -56,7 +56,7 @@ Feature: undefined step snippets return godog.ErrPending } - func featureContext(s *godog.Suite) { + 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) } @@ -87,7 +87,7 @@ Feature: undefined step snippets return godog.ErrPending } - func featureContext(s *godog.Suite) { + func FeatureContext(s *godog.Suite) { s.Step(`^I pull from github\.com$`, iPullFromGithubcom) s.Step(`^the project should be there$`, theProjectShouldBeThere) } diff --git a/fmt.go b/fmt.go index 66aa3bc..4e35933 100644 --- a/fmt.go +++ b/fmt.go @@ -30,7 +30,7 @@ var undefinedSnippetsTpl = template.Must(template.New("snippets").Funcs(snippetH return godog.ErrPending } -{{end}}func featureContext(s *godog.Suite) { {{ range . }} +{{end}}func FeatureContext(s *godog.Suite) { {{ range . }} s.Step({{ backticked .Expr }}, {{ .Method }}){{end}} } `))