diff --git a/Makefile b/Makefile index e64252b..18629a4 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,4 @@ test-unit: test-integration: @echo ">> integration test" - @$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -godog -race -v + @$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -race -v --godog diff --git a/expander_internal_test.go b/expander_internal_test.go index e54c934..fa21885 100644 --- a/expander_internal_test.go +++ b/expander_internal_test.go @@ -64,6 +64,11 @@ func TestChainExpanders(t *testing.T) { "WIFE": "Jane", } }, + func() Expander { + return func(s string) string { + return strings.ReplaceAll(s, "$DURATION", "and stay there for 3 days") + } + }, func(s string) string { return strings.ReplaceAll(s, "$FROM", "Paris") }, @@ -81,9 +86,9 @@ func TestChainExpanders(t *testing.T) { _ = os.Unsetenv("DATE") // nolint:errcheck }() - content := "On $DATE, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT" + content := "On $DATE, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT $DURATION" actual := expand(content) - expected := "On Thursday, John & Jane are going from Paris to Berlin by bus" + expected := "On Thursday, John & Jane are going from Paris to Berlin by bus and stay there for 3 days" assert.Equal(t, expected, actual) } diff --git a/features/bootstrap/godog_test.go b/features/bootstrap/godog_test.go index 3864b21..84366cd 100644 --- a/features/bootstrap/godog_test.go +++ b/features/bootstrap/godog_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/cucumber/godog" + "github.com/spf13/pflag" "github.com/stretchr/testify/assert" "github.com/nhatthm/expandog" @@ -35,7 +36,14 @@ var ( //nolint:gochecknoinits func init() { flag.BoolVar(&runGoDogTests, "godog", false, "Set this flag is you want to run godog BDD tests") - godog.BindFlags("godog.", flag.CommandLine, &opt) // nolint: staticcheck + godog.BindCommandLineFlags("godog.", &opt) +} + +func TestMain(m *testing.M) { + flag.Parse() + pflag.Parse() + + os.Exit(m.Run()) } func TestIntegration(t *testing.T) { diff --git a/go.mod b/go.mod index 9a74569..e8d5cc9 100644 --- a/go.mod +++ b/go.mod @@ -9,5 +9,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-memdb v1.3.2 // indirect + github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 ) diff --git a/step_test.go b/step_test.go index e0e489b..54cddac 100644 --- a/step_test.go +++ b/step_test.go @@ -26,6 +26,11 @@ func TestExpandStep(t *testing.T) { "WIFE": "Jane", } }, + func() expandog.Expander { + return func(s string) string { + return strings.ReplaceAll(s, "$DURATION", "and stay there for 3 days") + } + }, func(s string) string { return strings.ReplaceAll(s, "$FROM", "Paris") }, @@ -43,8 +48,8 @@ func TestExpandStep(t *testing.T) { _ = os.Unsetenv("GREETINGS") // nolint:errcheck }() - step := &godog.Step{Text: "$GREETINGS, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT"} - expected := "Hi Dave, John & Jane are going from Paris to Berlin by bus" + step := &godog.Step{Text: "$GREETINGS, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT $DURATION"} + expected := "Hi Dave, John & Jane are going from Paris to Berlin by bus and stay there for 3 days" expandog.ExpandStep(step, expanders...)