Tic Tac Toe (accessor error)

Hello, I am having trouble resolving an error that seems to be related to my instance variable accessors - specifically the @board accessor in my game.rb file.

The error message returned from running game_spec.rb:

  1) Game #board exposes a @board instance variable
 Failure/Error: Game.new(player_one, player_two)
   Double "player" received unexpected message :board= with (#<Board:0x007ff30dac6ae0 @grid=[[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]>)
 # ./lib/game.rb:15:in `initialize'
 # ./spec/game_spec.rb:9:in `new'
 # ./spec/game_spec.rb:9:in `block (2 levels) in <top (required)>'
 # ./spec/game_spec.rb:19:in `block (3 levels) in <top (required)>'

My accessor code:

class Game
  attr_accessor :board, :current_player, :player_one, :player_two

  def initialize(player_one, player_two)
    @player_one = player_one
    @player_two = player_two
    @board = Board.new

I can run my finished game successfully from the command line (and obviously this involves accessing @board), so I am confused. Should I strictly follow this spec, or is it okay if my slightly different design works? I’d like to solve the error regardless.


Hello Mike,
I think your initialize function look fine to me.
I would like to debug your code. Would you mind to send your Tic Tac Toe folder? (make it private message if you don’t want people to see your code)