On 2/22/07, <b class="gmail_sendername">Pat Maddox</b> &lt;<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>specify &quot;should find all users over the given age&quot; do<br>&nbsp;&nbsp;User.should_receive(:find).with(:all, :conditions =&gt; [&quot;age &gt; ?&quot;, 18])<br>&nbsp;&nbsp;User.find_older_than 18<br>end</blockquote><div><br>I don&#39;t have a good suggestion here, but an observation is that the spec is too fine-grained and brittle, which, as you mention below, inhibits refactoring and TDD flow, etc.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I don&#39;t know about you, but to me that sucks.&nbsp;&nbsp;There is no TDD rhythm<br>there.&nbsp;&nbsp;We write a failing spec, but it&#39;s a fairly complex spec.&nbsp;&nbsp;On
<br>top of that we&#39;ve basically implemented the method from within the<br>spec.&nbsp;&nbsp;That&#39;s not TDD.<br><br>We also can&#39;t refactor.&nbsp;&nbsp;Let&#39;s say that at some point we decided to<br>change the method to<br><br>def 
User.find_older_than(age)<br>&nbsp;&nbsp;find(:all).select {|u| u.age &gt; age }<br>end<br><br>Our spec would break, even though the semantics of<br>User.find_older_than hasn&#39;t changed.</blockquote><div>&nbsp;</div>I have experienced similar troubles as you have in the past, and the usage of mock-based testing in these scenarios still hasn&#39;t fully clicked for me either.&nbsp; I know something&#39;s not right, but I can&#39;t put my finger on what it is.&nbsp; I suspect it&#39;s that the APIs you&#39;re working with are too data-intensive and not message-intensive (
i.e., &quot;tell don&#39;t ask&quot;), which is where mock testing really shines.&nbsp; I&#39;ll defer to this post from Steve Freeman (there are probably other entries too that are similar), and the quote that apparently originates from Joe Walnes, &quot;Don&#39;t mock types you don&#39;t own&quot;.
<br><br><a href="http://stevef.truemesh.com/archives/000194.html">http://stevef.truemesh.com/archives/000194.html</a><br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m beginning to think that most of the time, you don&#39;t want to use a<br>test DB at all.&nbsp;&nbsp;When you&#39;re testing an AR model, just use an<br>in-memory record and stub any associations you need.&nbsp;&nbsp;But when you do<br>
do something that interacts with the database - like doing a custom<br>find - you need to use the database to make sure that you&#39;re getting<br>the right results.&nbsp;&nbsp;Whether you use fixtures or create some records in<br>
the setup method, you have to actually hit the db.</blockquote><div><br>I don&#39;t have a better answer, so maybe your instinct is right here -- don&#39;t fight with brittle mocks, if the database works for you and doesn&#39;t slow you down too much.
<br><br>I would think Dave, David and Aslak would have good input on this topic, and hope they have a moment to share their experiences.<br></div><br>Cheers,<br>/Nick<br></div>