
This was causing way to much investigating in order for me to find That I've only copied parts of the examples resulting in "flag".Parse instead of pflag.Parse()
65 строки
1,4 КиБ
Go
65 строки
1,4 КиБ
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/cucumber/godog"
|
|
"github.com/cucumber/godog/colors"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var opts = godog.Options{Output: colors.Colored(os.Stdout)}
|
|
|
|
func init() {
|
|
godog.BindCommandLineFlags("godog.", &opts)
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
pflag.Parse()
|
|
opts.Paths = pflag.Args()
|
|
|
|
status := godog.TestSuite{
|
|
Name: "godogs",
|
|
TestSuiteInitializer: InitializeTestSuite,
|
|
ScenarioInitializer: InitializeScenario,
|
|
Options: &opts,
|
|
}.Run()
|
|
|
|
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 InitializeTestSuite(ctx *godog.TestSuiteContext) {
|
|
ctx.BeforeSuite(func() { Godogs = 0 })
|
|
}
|
|
|
|
func InitializeScenario(ctx *godog.ScenarioContext) {
|
|
ctx.BeforeScenario(func(*godog.Scenario) {
|
|
Godogs = 0 // clean the state before every scenario
|
|
})
|
|
|
|
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
|
|
ctx.Step(`^I eat (\d+)$`, iEat)
|
|
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
|
|
}
|