Jack
Jack

Reputation: 763

why my failing Ruby Unit Test does not fail?

When I run in the terminal "ruby game_test.rb" nothing happens, can someone explain me why?

Here is the game.rb:

class Game
    attr_reader :number
    def initialize(number)
        @number = number
    end

    def return_number
        number
    end

    def make_array
        Array.new(number)
    end

    def fill_array
        array = make_array
        counter = 1
        array.each do |element|
            element = counter
            counter += 1
        end
        array
    end
end

and here is the test game_test.rb:

require_relative "game"
require "test/unit"

class GameTest < Test::Unit::TestCase


    def fill_array
        assert_equal(1, Game.new(50).fill_array)
    end
end

Upvotes: 0

Views: 38

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84132

A method must start with test_ for Test::Unit to think it is a test method and run it automatically, i.e.

class GameTest < Test::Unit::TestCase
  def test_fill_array
    assert_equal(1, Game.new(50).fill_array)
  end
end

Without the prefix, it thinks your method is just a helper used during your tests.

Upvotes: 1

Related Questions