Created
April 16, 2013 19:13
-
-
Save joebew42/5398713 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
require File.join(File.dirname(__FILE__), 'kata_bowling_game.rb') | |
describe Game, "Bowling main game class" do | |
let(:game) { Game.new } | |
def rolls_many(n, pins) | |
n.times { game.roll pins } | |
end | |
def rolls_spare | |
game.roll 5 | |
game.roll 5 | |
end | |
def rolls_strike | |
game.roll 10 | |
end | |
context "when creates a new game" do | |
it "returns an instance of Game" do | |
game = Game.new | |
game.should be_an_instance_of Game | |
end | |
end | |
context "when throw the ball" do | |
it "returns 0 if per each throw 0 pins were thrown down" do | |
rolls_many 20, 0 | |
game.score.should == 0 | |
end | |
it "returns 20 if per each throw 1 pin were thrown down" do | |
rolls_many 20, 1 | |
game.score.should == 20 | |
end | |
end | |
context "when thrown all pins with a spare" do | |
it "returns the right score with the bonus spare" do | |
rolls_spare | |
game.roll 3 | |
rolls_many 17, 0 | |
game.score.should == 16 | |
end | |
end | |
context "when thrown all pins with a strike" do | |
it "returns the right score with the bonus strike" do | |
rolls_strike | |
game.roll 3 | |
game.roll 4 | |
rolls_many 16, 0 | |
game.score.should == 24 | |
end | |
end | |
context "when play a perfect game" do | |
it "returns 300 points" do | |
rolls_many 12, 10 | |
game.score.should == 300 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment