Last active
January 4, 2016 07:59
-
-
Save mdwhatcott/8591946 to your computer and use it in GitHub Desktop.
Detailed example of the 2.0 update to GoConvey
This file contains hidden or 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
// NOTE: This is examples code which never actually became valid because we found a better way. | |
func TestScoring(t *testing.T) { | |
Convey("Subject: Bowling Game Scoring", t, func(c Context, so Assertion) { | |
var game *Game // Whatever you do, don't do this: game := NewGame() | |
// Otherwise nested closures won't reference the correct instance | |
Convey("Given a fresh score card", c, func() { | |
game = NewGame() | |
Convey("When all gutter balls are thrown", c, func() { | |
game.rollMany(20, 0) | |
Convey("The score should be zero", c, func() { | |
so(game.Score(), ShouldEqual, 0) | |
}) | |
}) | |
SkipConvey("When all throws knock down only one pin", c, func() { | |
game.rollMany(20, 1) | |
Convey("The score should be 20", c, func() { | |
so(game.Score(), ShouldEqual, 20) | |
}) | |
}) | |
Convey("When a spare is thrown", c, func() { | |
game.rollSpare() | |
game.Roll(3) | |
game.rollMany(17, 0) | |
Convey("The score should include a spare bonus.", c, func() { | |
so(game.Score(), ShouldEqual, 16) | |
}) | |
}) | |
Convey("When a strike is thrown", c, func() { | |
game.rollStrike() | |
game.Roll(3) | |
game.Roll(4) | |
game.rollMany(16, 0) | |
Convey("The score should include a strike bonus.", c, func() { | |
so(game.Score(), ShouldEqual, 24) | |
}) | |
}) | |
Convey("When all strikes are thrown", c, func() { | |
game.rollMany(21, 10) | |
Convey("The score should be 300.", c, func() { | |
so(game.Score(), ShouldEqual, 300) | |
}) | |
}) | |
Reset(c, func() { | |
game = nil // example of a simple Reset (optional) | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment