Skip to content

Instantly share code, notes, and snippets.

@MrJadaml
Created July 21, 2015 04:15
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/3ccaa2fb17144bc22673 to your computer and use it in GitHub Desktop.
Save MrJadaml/3ccaa2fb17144bc22673 to your computer and use it in GitHub Desktop.
RSpec Stage
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