Created
July 21, 2015 04:15
-
-
Save MrJadaml/3ccaa2fb17144bc22673 to your computer and use it in GitHub Desktop.
RSpec Stage
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 | |
let(:game) { Game.new } | |
context 'when starting a new game' do | |
it 'sets score to zero' do | |
expect(game.score).to eq(0) | |
end | |
it 'starts with no players' do | |
expect(game.players).to eq([]) | |
end | |
end | |
it 'can add players to the game' do | |
game.add_player('Buzz') | |
expect(game.players).to eq(['Buzz']) | |
end | |
it 'adds knocked down pins to score' do | |
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