Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How can I use the "test/unit" right

Reply
Thread Tools

How can I use the "test/unit" right

 
 
artoxvw@gmail.com
Guest
Posts: n/a
 
      05-14-2009
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 method `add_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:in
`assert_block'
from c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:83:in
`assert_equal'
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
 
Reply With Quote
 
 
 
 
Ryan Davis
Guest
Posts: n/a
 
      05-14-2009

On May 14, 2009, at 06:15 , http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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


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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
I use IE right now--Should I use Firefox or Mozilla? BOB Firefox 10 04-16-2006 08:23 PM
Tool to enable Right click on pages where Right click is disabled tsteinke@gmail.com Computer Support 4 08-28-2005 11:53 PM
Right-click context menu that can pass values when right-clicking a link?? Leon Javascript 3 11-26-2004 07:37 AM
pass the right form input to the right control Tom ASP .Net 0 12-11-2003 03:07 AM



Advertisments