Reputation: 3
I'm trying Ruby and Unit Testing but my simple attempts at running test cases are returning nothing. The curious thing is that the tests were running before and returning the number of tests that were ran and the number of assertions and so on. But for some reason they stopped running. I have two separated files:
#TipoMovimento.rb
class TipoMovimento
attr_accessor :designacao
attr_accessor :cor
attr_accessor :regras
def initialize(aDesignacao, aCor, asRegras)
@designacao = aDesignacao
@cor = aCor
@regras = asRegras
end
def ==(other)
other.class == self.class && other.state == self.state
end
def state
self.instance_variables.map { |variable| self.instance_variable_get variable }
end
end
and
#TesteTipoMovimento.rb
require './TipoMovimento.rb'
require 'test/unit'
class TesteTipoMovimento < Test::Unit::TestCase
def setup
@tm = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
end
def tc_equal
tm2 = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
assert_true(tm2 == @tm)
tm2 = TipoMovimento.new('Des2', 'Cor1', ['r1', 'r2'])
assert_false(tm2 == @tm)
end
end
Both files are in the same folder. Unfortunately, when I run the test file, nothing happens. After I press enter the prompt simply ignores my command. Something like:
C:\My Ruby Files\>ruby TesteTipoMovimento.rb
C:\My Ruby Files\>
This is obviously something simple that I'm missing, so if anyone could help me I would appreciate it. Thanks!
Upvotes: 0
Views: 272
Reputation: 230286
You have no tests in that test class. To make method a test, prefix its name with test_
.
class TesteTipoMovimento < Test::Unit::TestCase
def setup
@tm = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
end
def test_tc_equal
tm2 = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
assert_true(tm2 == @tm)
tm2 = TipoMovimento.new('Des2', 'Cor1', ['r1', 'r2'])
assert_false(tm2 == @tm)
end
end
Upvotes: 1