Created
July 21, 2015 04:17
-
-
Save MrJadaml/b849124fdef75e0d6032 to your computer and use it in GitHub Desktop.
RSpec Stage 5
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
require './game.rb' | |
describe Game do | |
it 'sets score to zero when starting a new game' do | |
game = Game.new | |
expect(game.score).to eq(0) | |
end | |
it 'starts with no players when starting a new game' do | |
game = Game.new | |
expect(game.players).to eq([]) | |
end | |
it 'can add players to the game' do | |
game = Game.new | |
game.add_player('Buzz') | |
expect(game.players).to eq(['Buzz']) | |
end | |
it 'adds knocked down pins to score' do | |
game = Game.new | |
pins = rand(11) | |
pins2 = rand(11) | |
game.roll(pins) | |
game.roll(pins2) | |
expect(game.score).to eq(pins + pins2) | |
end | |
end | |
============================================================================================================ | |
class Game | |
attr_reader :score, :players | |
def initialize | |
@score = 0 | |
@players = [] | |
end | |
def add_player(player) | |
@players << player | |
end | |
def roll(pins) | |
@score += pins | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment