How can I use the "test/unit" right

when I run the following code

require ‘test/unit’
class TC_Pram < Test::Unit::TestCase
def initialize(name)
@name=name
end
def test_array
puts assert_equal(2,@name[2])
end
end
tc=TC_Pram.new(“wang”)
tc.test_array

there are some errors as follows

c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:125:in add_assertion': undefined methodadd_assertion’ for nil:NilClass (NoMethodError)
from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:494:in
_wrap_assertion' from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:46:inassert_block’
from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:83:in
assert_equal' from test_unit.rb:7:intest_array’
from test_unit.rb:11

I don’t know how to resolve it , so I need your help , thanks

On May 14, 2009, at 06:15 , [email protected] wrote:

end
tc=TC_Pram.new(“wang”)
tc.test_array

require ‘test/unit’

class TC_Pram < Test::Unit::TestCase
def setup
@name = “wang”
end

def test_array
assert_equal ?n, @name[2]
end
end


nothing more. don’t add puts. don’t instantiate or call the method.
just run it with ruby. “require ‘test/unit’” will take care of the rest.

I changed your assertion so that it’ll pass. you may not have wanted
that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs