Newbie: Unit testing a private method with arguments

M

Marcus Lindemann

Hi,
I'm somewhat new to ruby. and I want to unit test my methods. Since I
compose my public methods from private ones, I start writing and also
test those first. From the web I found that testing of private methods
is possible through

class Foo
def foobar
bar
end

private
def bar # <-- takes no params
"bar"
end

def bla(aName)
aName
end
end

x = Foo.new
x.send:)bar)

However, when applying this to method bla, I don't have any idea on how
to pass any argument to bla. Can someone help me here?

Thanks
Marcus
 
E

Eric Hodel

Hi,
I'm somewhat new to ruby. and I want to unit test my methods. Since
I compose my public methods from private ones, I start writing and
also test those first. From the web I found that testing of private
methods is possible through

class Foo
def foobar
bar
end

private
def bar # <-- takes no params
"bar"
end

def bla(aName)
aName
end
end

x = Foo.new
x.send:)bar)

However, when applying this to method bla, I don't have any idea on
how to pass any argument to bla. Can someone help me here?

An easier way to do it is:

private unless $TESTING

But, send takes 1 or more arguments:

x.send :bla, 'Marcus Lindemann'

(And passes blocks along as well.)
 
D

Derek Chesterfield

$ ri send

------------------------------------------------------------ Object#send
obj.send(symbol [, args...]) => obj
obj.__send__(symbol [, args...]) => obj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top