The only reason I could see to do this would be to get around an access
prohibition. You can use send in this way to call a private or
protected method.
>
> William
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.
Ah, thanks, yes that will probably be the reason.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Then you've got bigger problems. You shouldn't be testing your private
methods; that's poking too deeply into an object's implementation. You
should only ever test things that can be called from outside an object.
If a private method is an intermediate value in a computation, just test
the end result. If a private method really needs to be tested
separately, then it's telling you that it wants to be public.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
Sent from my iPhone
David Kahn wrote in post #978011:
> On Thu, Jan 27, 2011 at 4:01 PM, William FiskThen you've got bigger problems. You shouldn't be testing your private
> <willia...@gmail.com>wrote:
>
>> Ah, thanks, yes that will probably be the reason.
>
>
> Right... send comes in real handy in testing private methods, use it all
> the
> time
methods; that's poking too deeply into an object's implementation. You
should only ever test things that can be called from outside an object.
If a private method is an intermediate value in a computation, just test
the end result. If a private method really needs to be tested
separately, then it's telling you that it wants to be public.
Sent from my iPhone
--
And therefore it is the only thing that is worth testing. No one cares
what your private logic is like, because they never see it.
> regardless of complexity or size, where the private logic may actually
> be
> the most complex, being called by a relatively light public function.
Then test the return from the "light" public function, or make your
private logic public.
> Now
> this may be a difference between TDD and BDD in pure forms, but for me I
> find if I drive my methods, public or private with test first, that the
> end
> resulting code is much more pliable.
No private method should have a test at all. That's testing
implementation, and therefore is bad. You want to test interface only.
> Also, if I have coverage on what
> becomes complex private logic, at a more granular level -- then I have a
> much stronger project an also address minute issues closer to the
> source.
No! All you have is brittle, implementation-dependent tests. What you
*think* is improving the quality of your code is actually hindering it.
> I
> am sure you have your method of working that works for you, this is what
> I
> have found effective and successful.
But it is neither. This is a matter of principles, not taste. Please
do not handwave away what I am telling you by saying that it is a matter
of taste -- these are principles you need to understand. If you want to
disagree after you understand the principles, I will be interested to
hear your reasoning.
It is *ineffective* to test private methods because you never care about
the return value from a private method as such -- if you cared about the
return value, you'd have made the method public.
It is *unsuccessful* to test private methods because you are tying your
tests too closely to implementation, which means they will fail if you
change your implementation -- this despite the fact that one of the
points of testing is to tell you that your code still works when you
refactor your implementation.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.
If a private method is an intermediate value in a computation, just test
the end result. If a private method really needs to be tested
separately, then it's telling you that it wants to be public.
I disagree -- for me public is what I want to expose to outside access, regardless of complexity or size, where the private logic may actually be the most complex, being called by a relatively light public function. Now this may be a difference between TDD and BDD in pure forms, but for me I find if I drive my methods, public or private with test first, that the end resulting code is much more pliable. Also, if I have coverage on what becomes complex private logic, at a more granular level -- then I have a much stronger project an also address minute issues closer to the source. I am sure you have your method of working that works for you, this is what I have found effective and successful.
The XP crowd have been a major influence on my testing philosophy, even
though I've never done XP as such.
> It took me a while to get
> used to the approach, and I think it's important to clarify that Marnen
> isn't saying not to test complex private methods.
Well, I guess I sort of *am* saying that, but only in the sense that you
probably shouldn't *have* complex private methods that need their own
tests -- that is, if your private methods are that complex, they should
be made public and/or decomposed.
> He's just saying that
> if they are complex, maybe you've discovered another composed object's
> public method.
Or the same object's public method, or a method that is too long...
> SRP and all that . . .
I suppose. Basically, I think if you have a private method that is
complex enough that wants to be tested in isolation, then that is a
symptom of an underlying design problem: your methods are insufficiently
accessible, or insufficiently atomic, or your code is otherwise
insufficiently modular (say, by virtue of needing a new class
introduced). Fix the underlying problem and the need for
"so-big-it-needs-its-own-tests" private methods will go away.
>
> Best Wishes,
> Peter
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.