Created
June 5, 2017 22:38
-
-
Save anshumanbh/5b057a0f5d9a6c3c12c2e65e93a47bdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"testing" | |
"time" | |
"github.com/DATA-DOG/godog" | |
) | |
func TestMain(m *testing.M) { | |
status := godog.RunWithOptions("godogs", func(s *godog.Suite) { | |
FeatureContext(s) | |
}, godog.Options{ | |
Format: "progress", | |
Paths: []string{"features"}, | |
Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order | |
}) | |
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(interface{}) { | |
Godogs = 0 // clean the state before every scenario | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment