<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments for confabulus</title>
	<atom:link href="http://blog.confabulus.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.confabulus.com</link>
	<description>rails, coding, and the goings on at confabulus</description>
	<pubDate>Wed, 07 Jan 2009 13:04:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on testing protected and private methods in ruby by Luke Redpath</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-23</link>
		<dc:creator>Luke Redpath</dc:creator>
		<pubDate>Wed, 29 Oct 2008 09:47:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-23</guid>
		<description>"Why not test both if you have the luxury?"

Because of all of the problems I mention above. If you have code paths that aren't being exercised by a public API, then delete them.

Another point is: if you're writing private methods up front rather than extracting them from (already tested) public methods, then you're probably making design decisions too early. If you're following a TDD approach, you're writing the simplest thing that works then refactoring later - this would typically involve extracting common code into private methods (to remove duplication or introducing explaining methods) - but the behaviour hasn't changed and you already have tests in place that go through your public api. At this point, adding direct tests for these extracted private methods gives you nothing; they should already be covered.

Again, as I said before, if you have a large number of private methods that seem to be doing a lot of related things, then extract them into a new class and test that as an isolated unit.

I'm yet to see any convincing arguments as to why you should break encapsulation and test private methods directly but I think I've presented numerous reason why you shouldn't - high coupling between tests and implementation leading to difficult refactoring, obscuring poor design decisions and redundant test code.

Your client code will only be (or should be) using your class under test through it's public API - your tests should do the same.</description>
		<content:encoded><![CDATA[<p>&#8220;Why not test both if you have the luxury?&#8221;</p>
<p>Because of all of the problems I mention above. If you have code paths that aren&#8217;t being exercised by a public API, then delete them.</p>
<p>Another point is: if you&#8217;re writing private methods up front rather than extracting them from (already tested) public methods, then you&#8217;re probably making design decisions too early. If you&#8217;re following a TDD approach, you&#8217;re writing the simplest thing that works then refactoring later - this would typically involve extracting common code into private methods (to remove duplication or introducing explaining methods) - but the behaviour hasn&#8217;t changed and you already have tests in place that go through your public api. At this point, adding direct tests for these extracted private methods gives you nothing; they should already be covered.</p>
<p>Again, as I said before, if you have a large number of private methods that seem to be doing a lot of related things, then extract them into a new class and test that as an isolated unit.</p>
<p>I&#8217;m yet to see any convincing arguments as to why you should break encapsulation and test private methods directly but I think I&#8217;ve presented numerous reason why you shouldn&#8217;t - high coupling between tests and implementation leading to difficult refactoring, obscuring poor design decisions and redundant test code.</p>
<p>Your client code will only be (or should be) using your class under test through it&#8217;s public API - your tests should do the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by gaffo</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-22</link>
		<dc:creator>gaffo</dc:creator>
		<pubDate>Wed, 29 Oct 2008 02:46:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-22</guid>
		<description>Radarek: Thanks. I didn't run this through an interpreter before I posted it. Good Eye.</description>
		<content:encoded><![CDATA[<p>Radarek: Thanks. I didn&#8217;t run this through an interpreter before I posted it. Good Eye.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Alex Pooley</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-21</link>
		<dc:creator>Alex Pooley</dc:creator>
		<pubDate>Wed, 29 Oct 2008 01:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-21</guid>
		<description>Private methods exist to capture common code within a class. Assuming you may use that private method again it's nice peace of mind to know that it's logically correct.

You may not exercise the private method via the current class interface, but at a later date you may add another method and you may find an issue in your private method indirectly while testing your new method. I would rather catch the problem with the private code right after writing it than fuddling through an error on an indirect method call a few months later.

Why not test both if you have the luxury? :)</description>
		<content:encoded><![CDATA[<p>Private methods exist to capture common code within a class. Assuming you may use that private method again it&#8217;s nice peace of mind to know that it&#8217;s logically correct.</p>
<p>You may not exercise the private method via the current class interface, but at a later date you may add another method and you may find an issue in your private method indirectly while testing your new method. I would rather catch the problem with the private code right after writing it than fuddling through an error on an indirect method call a few months later.</p>
<p>Why not test both if you have the luxury? <img src='http://blog.confabulus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Luke Redpath</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-16</link>
		<dc:creator>Luke Redpath</dc:creator>
		<pubDate>Tue, 28 Oct 2008 23:33:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-16</guid>
		<description>If you're testing your public methods, and they are invoking your private methods, then your private method code *is* being testing, that's the point. Testing private methods directly (out of context) has no value at all.</description>
		<content:encoded><![CDATA[<p>If you&#8217;re testing your public methods, and they are invoking your private methods, then your private method code *is* being testing, that&#8217;s the point. Testing private methods directly (out of context) has no value at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Amos King</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-15</link>
		<dc:creator>Amos King</dc:creator>
		<pubDate>Tue, 28 Oct 2008 19:48:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-15</guid>
		<description>I concede the fact that testing private methods may be driving design too much, and  can lead to painful refactoring.  Painful refactoring may lead to worse code in the end.

If you have private methods, test them!  If you aren't testing private methods move them to another class and test that.    This is a much better practice and may lead to more reused code.</description>
		<content:encoded><![CDATA[<p>I concede the fact that testing private methods may be driving design too much, and  can lead to painful refactoring.  Painful refactoring may lead to worse code in the end.</p>
<p>If you have private methods, test them!  If you aren&#8217;t testing private methods move them to another class and test that.    This is a much better practice and may lead to more reused code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Luke Redpath</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-14</link>
		<dc:creator>Luke Redpath</dc:creator>
		<pubDate>Tue, 28 Oct 2008 18:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-14</guid>
		<description>Just to clarify, the reason I find that assertion to be bad advice is because it could lead to the assumption that just because you've written a test "for every method", that your class is well tested, when it may not be.

The fact that you have to jump through hoops to test private methods should tell you that it's probably not the right thing.</description>
		<content:encoded><![CDATA[<p>Just to clarify, the reason I find that assertion to be bad advice is because it could lead to the assumption that just because you&#8217;ve written a test &#8220;for every method&#8221;, that your class is well tested, when it may not be.</p>
<p>The fact that you have to jump through hoops to test private methods should tell you that it&#8217;s probably not the right thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Luke Redpath</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-13</link>
		<dc:creator>Luke Redpath</dc:creator>
		<pubDate>Tue, 28 Oct 2008 18:05:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-13</guid>
		<description>"In fact testing of every method in a class is a great practice."

I find this assertion to be completely wrong and bad advice.

It's not about testing methods, it's about testing behaviour. Your behaviour should be exercised through it's public interface (just like your client code) otherwise what's the point of access control? You should be able to free to refactor the internals of your class (private methods) without breaking anything, including your unit tests. Private methods aren't behaviour, they are pure implementation detail. As I said before; if you find a lot of stuff happening in your private methods, then maybe there is a hidden class waiting to be extracted. Extract it, then test the new classes public interface.

Remember, refactoring is the process of changing the code without changing it's behaviour; if you test the code at its lowest level (private methods) instead of testing the behaviour you are testing the wrong thing and creating strong coupling between your tests and your code, making refactoring harder.</description>
		<content:encoded><![CDATA[<p>&#8220;In fact testing of every method in a class is a great practice.&#8221;</p>
<p>I find this assertion to be completely wrong and bad advice.</p>
<p>It&#8217;s not about testing methods, it&#8217;s about testing behaviour. Your behaviour should be exercised through it&#8217;s public interface (just like your client code) otherwise what&#8217;s the point of access control? You should be able to free to refactor the internals of your class (private methods) without breaking anything, including your unit tests. Private methods aren&#8217;t behaviour, they are pure implementation detail. As I said before; if you find a lot of stuff happening in your private methods, then maybe there is a hidden class waiting to be extracted. Extract it, then test the new classes public interface.</p>
<p>Remember, refactoring is the process of changing the code without changing it&#8217;s behaviour; if you test the code at its lowest level (private methods) instead of testing the behaviour you are testing the wrong thing and creating strong coupling between your tests and your code, making refactoring harder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Amos</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-12</link>
		<dc:creator>Amos</dc:creator>
		<pubDate>Tue, 28 Oct 2008 15:00:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-12</guid>
		<description>There is nothing wrong with testing private methods.  In fact testing of every method in a class is a great practice.  It all depends on your tolerance level for typing more code in your tests.  At some point you will get tired of having to jump through hoops on testing and it will drive you to refactor that section.  If you aren't testing the methods directly you may not notice the amount of code you in private methods.

Instead of making a method public for testing use instance_eval:

class UserTest  "Mike", :last_name =&#62; "Gaffney") 
    assert_equal("Gaffney, Mike", user.instance_eval {full_name}) 
  end 
end

Decide what is the best way for you to know when it is time to refactor.</description>
		<content:encoded><![CDATA[<p>There is nothing wrong with testing private methods.  In fact testing of every method in a class is a great practice.  It all depends on your tolerance level for typing more code in your tests.  At some point you will get tired of having to jump through hoops on testing and it will drive you to refactor that section.  If you aren&#8217;t testing the methods directly you may not notice the amount of code you in private methods.</p>
<p>Instead of making a method public for testing use instance_eval:</p>
<p>class UserTest  &#8220;Mike&#8221;, :last_name =&gt; &#8220;Gaffney&#8221;)<br />
    assert_equal(&#8221;Gaffney, Mike&#8221;, user.instance_eval {full_name})<br />
  end<br />
end</p>
<p>Decide what is the best way for you to know when it is time to refactor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Radarek</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-11</link>
		<dc:creator>Radarek</dc:creator>
		<pubDate>Tue, 28 Oct 2008 11:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-11</guid>
		<description>Also instead of:
class UserTest &#60;&#60; Test::Unit
it should be
class UserTest &#60; Test::Unit</description>
		<content:encoded><![CDATA[<p>Also instead of:<br />
class UserTest &lt;&lt; Test::Unit<br />
it should be<br />
class UserTest &lt; Test::Unit</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on testing protected and private methods in ruby by Radarek</title>
		<link>http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/comment-page-1/#comment-10</link>
		<dc:creator>Radarek</dc:creator>
		<pubDate>Tue, 28 Oct 2008 11:50:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.confabulus.com/?p=31#comment-10</guid>
		<description>Are you sure that super.full_name works for you? "super" means "call the same method but with definition from next ancestor of this class" and you call "full_name" on returned value by super.

http://pastie.org/302159</description>
		<content:encoded><![CDATA[<p>Are you sure that super.full_name works for you? &#8220;super&#8221; means &#8220;call the same method but with definition from next ancestor of this class&#8221; and you call &#8220;full_name&#8221; on returned value by super.</p>
<p><a href="http://pastie.org/302159" rel="nofollow">http://pastie.org/302159</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
