Skip to content

Instantly share code, notes, and snippets.

@MrJadaml
Created July 21, 2015 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrJadaml/b849124fdef75e0d6032 to your computer and use it in GitHub Desktop.
Save MrJadaml/b849124fdef75e0d6032 to your computer and use it in GitHub Desktop.
RSpec Stage 5
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