[rspec-users] spec-ing private methods?

Matt Wynne matt at mattwynne.net
Wed Oct 14 17:33:44 EDT 2009


On 14 Oct 2009, at 20:49, Scott Taylor wrote:

> On Oct 14, 2009, at 3:36 PM, Joaquin Rivera Padron wrote:
>
>> hello there,
>> how do you tipically spec private methods? The thing is Ï have  
>> something like this:
>
> You have a few options:
>
> 1. Make the method public in the object you are testing
> 2. Make the method public in the test case
> 3. Don't test the method
> 4. Use __send__ or (send) to call it.
> 5. Refactor private methods to a new object, and make the methods  
> public in that object.
>
> Most of those options suck (esp. 1, 2, 3, & 4) - usually it  
> represents a design flaw (you are doing too much in your class).

Yup. Sprout class[1] works for me, every single time.

[1]http://xunitpatterns.com/Sprout%20Class.html

cheers,
Matt

+447974 430184
matt at mattwynne.net
http://mattwynne.net



More information about the rspec-users mailing list