diff options
| author | Teddy Wing | 2015-04-16 02:13:04 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-04-16 02:13:04 -0400 |
| commit | 6984fc31370564332ceab60c203cd6f1e695d61a (patch) | |
| tree | a53d6b3ecf3c1ba4f35fcd245c30757e1a266e11 /spec/player_spec.rb | |
| parent | fa951e520b7637d9e67c31a0a8b61733e253f90b (diff) | |
| parent | 93351518faf3bb4f63b4a3cc1ef28f5c06e09f01 (diff) | |
| download | tic-tac-toe-master.tar.bz2 | |
Diffstat (limited to 'spec/player_spec.rb')
| -rw-r--r-- | spec/player_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/player_spec.rb b/spec/player_spec.rb new file mode 100644 index 0000000..11bfd35 --- /dev/null +++ b/spec/player_spec.rb @@ -0,0 +1,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 |
