aboutsummaryrefslogtreecommitdiffstats
path: root/spec/board_spec.rb
blob: 8d2b8da562db0078c38f025879155b4eb862529f (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
require 'spec_helper'

describe Board do
  before do
    @board = Board.new
  end
  
  describe '#render' do
    it 'prints a grid' do
      @board.render.must_equal <<EOF
...
...
...
EOF
    end
    
    it 'starts with a grid of dots' do
      @board.instance_variable_get('@board').must_equal [
        ['.', '.', '.'],
        ['.', '.', '.'],
        ['.', '.', '.']
      ]
    end
  end
  
  describe '#transform_coordinates' do
    it 'converts string coordinates to an array' do
      @board.transform_coordinates('0,4').must_equal [0, 4]
    end
    
    it "returns nil if coordinates don't match the format" do
      @board.transform_coordinates('4').must_be_nil
      @board.transform_coordinates('4 2').must_be_nil
      @board.transform_coordinates('booyakacha').must_be_nil
      @board.transform_coordinates('booya,kacha').must_be_nil
    end
  end
end