63 строки
1,3 КиБ
Go
63 строки
1,3 КиБ
Go
/* file: $GOPATH/src/godogs/godogs_test.go */
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/cucumber/godog"
|
|
"github.com/cucumber/godog/colors"
|
|
messages "github.com/cucumber/messages-go/v10"
|
|
)
|
|
|
|
var opt = godog.Options{Output: colors.Colored(os.Stdout)}
|
|
|
|
func init() {
|
|
godog.BindFlags("godog.", flag.CommandLine, &opt)
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
flag.Parse()
|
|
opt.Paths = flag.Args()
|
|
|
|
status := godog.RunWithOptions("godogs", func(s *godog.Suite) {
|
|
FeatureContext(s)
|
|
}, opt)
|
|
|
|
if st := m.Run(); st > status {
|
|
status = st
|
|
}
|
|
os.Exit(status)
|
|
}
|
|
|
|
func thereAreGodogs(available int) error {
|
|
Godogs = available
|
|
return nil
|
|
}
|
|
|
|
func iEat(num int) error {
|
|
if Godogs < num {
|
|
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs)
|
|
}
|
|
Godogs -= num
|
|
return nil
|
|
}
|
|
|
|
func thereShouldBeRemaining(remaining int) error {
|
|
if Godogs != remaining {
|
|
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
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)
|
|
|
|
s.BeforeScenario(func(*messages.Pickle) {
|
|
Godogs = 0 // clean the state before every scenario
|
|
})
|
|
}
|