Forum: Ruby How can I use the "test/unit" right

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Artoxvw A. (Guest)
on 2009-05-14 17:15
(Received via mailing list)
when I run the following code

require 'test/unit'
class TC_Pram < Test::Unit::TestCase
  def initialize(name)
  def test_array
     puts assert_equal(2,@name[2])

there are some errors as follows

c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:125:in `add_assertion':
undefined method `add_assertion' for nil:NilClass (NoMethodError)
 from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:494:in
 from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:46:in
 from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:83:in
 from test_unit.rb:7:in `test_array'
 from test_unit.rb:11

I don't know how to resolve it , so I need  your help , thanks
Ryan D. (Guest)
on 2009-05-15 00:18
(Received via mailing list)
On May 14, 2009, at 06:15 , removed_email_address@domain.invalid wrote:

> end
> tc.test_array

require 'test/unit'

class TC_Pram < Test::Unit::TestCase
   def setup
     @name = "wang"

   def test_array
     assert_equal ?n, @name[2]


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
This topic is locked and can not be replied to.