Code Works but Tests Fail

I have been working on a Connect 4 game with a friend.  We are doing this for the Odin Project’s testing section.  The game works, but I cannot get the tests to pass.

Note:  This is solved, see the comment.

Below is an image of the board:

connect4 board

If a player drops 4 tokens in a row, that player wins:


My code is working fine, but when I run tests on the method which checks for a win, the tests fail.

The relevant tests are:


The first of these tests passes fine, because the starting value of game.won? is false.  In order to break out of the game loop, game.won? is changed to true:


But I can’t get the tests to pass for the life of me.  I’ve tried expect(game.won?).to eq(true), expect(game.won?).to be_true, expect(game.won?).to be_truthy, and still nothing works. I put the analyze_board function into its own module, and added the question at the end asking if you want to start a new game, so the game doesn’t exit immediately.  Still no luck!

The code is on my github if anyone wants to take a look.

One thought on “Code Works but Tests Fail”

  1. The solution is simple enough: the tests didn’t call the analyze_board function that returns @won. This was one of those doh! moments.

Leave a Reply

Your email address will not be published. Required fields are marked *