Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Newbie: Unit testing a private method with arguments

Reply
Thread Tools

Newbie: Unit testing a private method with arguments

 
 
Marcus Lindemann
Guest
Posts: n/a
 
      10-26-2005
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
 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      10-26-2005

On Oct 26, 2005, at 12:12 PM, Marcus Lindemann wrote:

> 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.)

--
Eric Hodel - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04




 
Reply With Quote
 
 
 
 
Derek Chesterfield
Guest
Posts: n/a
 
      10-27-2005
$ ri send

------------------------------------------------------------ Object#send
obj.send(symbol [, args...]) => obj
obj.__send__(symbol [, args...]) => obj
------------------------------------------------------------------------
Invokes the method identified by _symbol_, passing it any
arguments
specified. You can use +_send_+ if the name +send+ clashes with an
existing method in _obj_.

On 26 Oct 2005, at 8:12pm, Marcus Lindemann wrote:

> 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
>
>




 
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
[ANN] Webinar - Testing the Untestable - Unit Testing Dependenciesand Legacy Code in C++ Avi C++ 0 06-06-2012 11:25 AM
unit-profiling, similar to unit-testing Ulrich Eckhardt Python 6 11-18-2011 02:00 AM
Unit testing errors (testing the platform module) John Maclean Python 1 04-13-2010 02:11 PM
Test::Unit - Ruby Unit Testing Framework Questions Bill Mosteller Ruby 0 10-22-2009 02:02 PM
unit testing private methods jimgardener Java 4 08-13-2008 07:12 PM



Advertisments