On Oct 14, 2009, at 4:24 PM, Nicolás Sanguinetti wrote:

On Wed, Oct 14, 2009 at 5:49 PM, Scott Taylor <sc...@railsnewbie.com> 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:

def some_method
   complex_method + other_complex_methods
end

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

3 is ok.

Yeah, 3 is OK, although ideally you *are* testing the method, albeit indirectly through the public interface.

Scott


A "private" method just means it's an implementation detail that is
outside of your API. If you are aiming to test the behavior of your
API, then you don't care about implementation details.

-foca


am I?

thanks in advance,
joaquin

--
www.least-significant-bit.com
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to