Skip to content

Instantly share code, notes, and snippets.

@beathyate
Created September 27, 2011 19:11
Show Gist options
  • Save beathyate/1245938 to your computer and use it in GitHub Desktop.
Save beathyate/1245938 to your computer and use it in GitHub Desktop.
This is the rspec file of my project
class Game
attr_accessor :grid
def initialize
@grid = Hash.new
@moves = 0
9.times { |time| grid[time+1] = nil }
end
def mark(space, marker)
@grid[space] = marker
end
def move
result = @moves % 2 == 0 ? :X : :Y
@moves += 1
result
end
end
$LOAD_PATH << './app'
require 'rspec'
require 'game'
#Tic-tac-Toe Game TDD
describe Game do
before { @game = Game.new }
subject { @game }
context "with nine spaces grid" do
subject { @game.grid.size }
it { should be 9}
end
describe :mark do
subject { @game.grid[1] }
context "mark a space with X" do
before { @game.mark(1, :X) }
it { should be :X }
end
context "mark a space with Y" do
before { @game.mark(1, :Y) }
it { should be :Y }
end
end
describe :move do
subject { @game.move }
context "when an user does a first move" do
it { should be :X }
end
context "when an user does a next move after X move" do
before { @game.move }
it { should be :Y }
end
context "when an user does a next move after Y move" do
before { 2.times { @game.move } }
it { should be :X }
end
end
describe :winner do
subject { @game.get_winner }
#123
context "when three X marks are placing horizontal in a row" do
before do
@game.mark(1, :X)
@game.mark(2, :X)
@game.mark(3, :X)
end
it { should be :X }
end
#456
context "when three X marks are placing horizontal in a row" do
before do
@game.mark(4, :X)
@game.mark(5, :X)
@game.mark(6, :X)
end
it { should be :X }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment