github.com/lonnblad/godog@v0.7.14-0.20200306004719-1b0cb3259847/_examples/godogs/godogs_test.go (about) 1 /* file: $GOPATH/src/godogs/godogs_test.go */ 2 package main 3 4 import ( 5 "flag" 6 "fmt" 7 "os" 8 "testing" 9 10 messages "github.com/cucumber/messages-go/v9" 11 "github.com/lonnblad/godog" 12 "github.com/lonnblad/godog/colors" 13 ) 14 15 var opt = godog.Options{Output: colors.Colored(os.Stdout)} 16 17 func init() { 18 godog.BindFlags("godog.", flag.CommandLine, &opt) 19 } 20 21 func TestMain(m *testing.M) { 22 flag.Parse() 23 opt.Paths = flag.Args() 24 25 status := godog.RunWithOptions("godogs", func(s *godog.Suite) { 26 FeatureContext(s) 27 }, opt) 28 29 if st := m.Run(); st > status { 30 status = st 31 } 32 os.Exit(status) 33 } 34 35 func thereAreGodogs(available int) error { 36 Godogs = available 37 return nil 38 } 39 40 func iEat(num int) error { 41 if Godogs < num { 42 return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs) 43 } 44 Godogs -= num 45 return nil 46 } 47 48 func thereShouldBeRemaining(remaining int) error { 49 if Godogs != remaining { 50 return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs) 51 } 52 return nil 53 } 54 55 func FeatureContext(s *godog.Suite) { 56 s.Step(`^there are (\d+) godogs$`, thereAreGodogs) 57 s.Step(`^I eat (\d+)$`, iEat) 58 s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining) 59 60 s.BeforeScenario(func(*messages.Pickle) { 61 Godogs = 0 // clean the state before every scenario 62 }) 63 }