[rspec-users] spec-ing private methods?
Ashley Moran
ashley.moran at patchspace.co.uk
Wed Oct 14 16:32:43 EDT 2009
On 14 Oct 2009, at 20:49, Scott Taylor wrote:
> On Oct 14, 2009, at 3:36 PM, Joaquin Rivera Padron wrote:
>
>> private
>> def complex_method...
>> def other_complex_methods ...
>>
>> and the two complex methods can get really tricky to get right, I
>> would like to be able to write specs for them, how do you do that?
>> I mean I cannot do:
>>
>> object.some_private_method
>
> 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).
I'm with Scott, this usually indicates a design flaw, and 5 is usually
the solution. The clue is in the names you gave them - you shouldn't
have complex methods, especially private ones.
Can you post any of the code so we can see where the complexity/
problem is?
Ashley
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
More information about the rspec-users
mailing list