[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

testing a singleton method....

Feng Tien

4/8/2008 6:19:00 AM

Trying to pass a unit test;

def test_singleton_method
string1 = "hello"
string2 = "world"

assert string1.respond_to?(:only_one)
assert !string2.respond_to?(:only_one)
end

====

my code to pass it:

string1 = "hello"
string2 = "world"

def string1.only_one
puts "PLEASE WORK"
end


===

yet, this doesn't work, is there something I'm missing?
--
Posted via http://www.ruby-....

2 Answers

Paul McMahon

4/8/2008 6:33:00 AM

0

I'm not exactly sure what you are trying to test, but this works:

def test_singleton_method
string1 = "hello"
string2 = "world"
def string1.only_one
puts "PLEASE WORK"
end
assert string1.respond_to?(:only_one)
assert !string2.respond_to?(:only_one)
end

Julian Leviston

4/8/2008 6:47:00 AM

0

Could you post more context?

Chances are the singleton you *think* you're testing is not the same
instance you actually *are* testing.

Julian.



Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!
http://sensei.ze...


On 08/04/2008, at 4:18 PM, Feng Tien wrote:

> Trying to pass a unit test;
>
> def test_singleton_method
> string1 = "hello"
> string2 = "world"
>
> assert string1.respond_to?(:only_one)
> assert !string2.respond_to?(:only_one)
> end
>
> ====
>
> my code to pass it:
>
> string1 = "hello"
> string2 = "world"
>
> def string1.only_one
> puts "PLEASE WORK"
> end
>
>
> ===
>
> yet, this doesn't work, is there something I'm missing?
> --
> Posted via http://www.ruby-....
>