aboutsummaryrefslogtreecommitdiffstats
path: root/spec/player_spec.rb
blob: 11bfd35c19812d97576ce466d34a1ca6a7b6299d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'
require 'board'
require 'player'

describe Player do
  describe 'insignias' do
    it 'knows what an X insignia is' do
      Player::INSIGNIAS[:x].must_equal 'X'
    end
    
    it 'knows what an O insignia is' do
      Player::INSIGNIAS[:o].must_equal 'O'
    end
  end
  
  describe '#insignia' do
    it 'must be the correct insignia' do
      insignia = Player::INSIGNIAS[:o]
      player = Player.new(insignia, Board.new)
      player.insignia.must_equal insignia
    end
  end
  
  describe '#move' do
    before do
      @board = Board.new
      @player = Player.new(Player::INSIGNIAS[:x], @board)
    end
    
    it 'raises an ArgumentError given nil coordinates' do
      -> { @player.move(nil) }.must_raise ArgumentError
    end
    
    it 'adds a piece to the correct coordinates on `board`' do
      @player.move([1, 2])
      @board.instance_variable_get(:@board)[1][2].must_equal \
        @player.instance_variable_get(:@insignia)
    end
    
    it 'uses the correct insignia for the move' do
      insignia = Player::INSIGNIAS[:o]
      player = Player.new(insignia, @board)
      player.move([0, 1])
      @board.instance_variable_get(:@board)[0][1].must_equal insignia
    end
  end
end