Testing the `#formatted_grid` in the TicTacToe Ruby project


#1

Edit: I should probably say I’m following along the suggested tutorial at the bottom of the lesson…

So, I’m wrapping up the TicTacToe project within the Ruby module, but I still have a little ways to go.

I’ve added the #formatted_grid method found in the GitHub repo, and it works. Though I’m attempting to build a test for it in RSpec because: RSpec.

I’ve created a passing test, though I’m not certain if the stubbing I’m doing goes to far to get a false-positive. I’m going to post to SO, but I wanted to post here first, since I’m hoping there’s a little more familiarity with the content.

Here’s the ‘context’ with the ‘unit test’ that I wrote. I need to preface this with: I am using the TestCell Struct implemented when testing the #game_over method:

context '#formatted_grid' do
  it "puts an empty grid to start the game" do
    grid = [
          [empty, empty, empty],
          [empty, empty, empty],
          [empty, empty, empty]
    ]
    board = Board.new(grid: grid)
    allow(empty.value).to receive(:value?) { true }
    expect(board.formatted_grid).to eq([[empty,empty,empty],[empty,empty,empty],[empty,empty,empty]]
  end

end

My question is: Does this test create a false-positive?

I believe that it doesn’t; because the #formatted_grid is intended to merely display the grid in a formatted way, which this test does… though I could be taking a shortcut to the answer I expect and doing myself a disservice.

Any feedback is appreciated.