Forum: RSpec private methode

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4d6cd907dcbed99b2c472a5e652dce6b?d=identicon&s=25 Anita Anita (anita)
on 2008-10-10 21:40
Hi,

Can I test private methods directly?
Or should I pass by the methods that are calling these private methods?
Or can I make the method private after testing?
What is the best way?

Thank you
874be46e8593deadb2cec84b70b26725?d=identicon&s=25 Yi Wen (hayafirst)
on 2008-10-10 22:08
(Received via mailing list)
IMHO, one should never directly test a private method. So I prefer the
second way you mentioned in your email.

Better yet, think of why you want to test a private method. Is it too
complicated? If this is the case, way too often this private method
should
not really belong to the class it's currently in. This class might be
doing
too much and this private method is not part of core functionality this
class provides (or else it should be made public as part of the class's
interface). So you may want to refactor the code to find a proper home
for
your private method and make it public in that class and you can unit
testing this new public method.

Yi
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-10-10 22:13
(Received via mailing list)
Anita Anita <lists@ruby-forum.com> writes:

> Hi,
>
> Can I test private methods directly?
> Or should I pass by the methods that are calling these private methods?
> Or can I make the method private after testing?
> What is the best way?
>
> Thank you

The party line is not to test private methods.  Either test them
indirectly via a public method, or extract it to a separate object and
make it public there.

Pat
4d6cd907dcbed99b2c472a5e652dce6b?d=identicon&s=25 Anita Anita (anita)
on 2008-10-10 22:18
Well, it's a methods for buying with credit card info and everything. So
I wanted to test it to make sure that all my code works but I can't make
it public.
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-10-11 00:01
(Received via mailing list)
On 10 Oct 2008, at 21:18, Anita Anita wrote:

> but I can't make it public.

Why not? Who are you afraid is going to call it that shouldn't?
This topic is locked and can not be replied to.