<div dir="ltr">Took me a couple of reads to understand this aswell - but I&#39;m very much in favour of it.&nbsp; <br><br><div class="gmail_quote">On Mon, Sep 15, 2008 at 2:34 PM, Zach Dennis <span dir="ltr">&lt;<a href="mailto:zach.dennis@gmail.com">zach.dennis@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">On Sat, Sep 13, 2008 at 1:56 PM, Pat Maddox &lt;<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>&gt; wrote:<br>

&gt; I&#39;m pretty set on this (though I&#39;ll hold off on making changes<br>
&gt; until I feel all opinions are given thorough discussion). &nbsp;But there&#39;s<br>
&gt; one case where it&#39;s not 100% clear to me what to do were we to make<br>
&gt; these changes.<br>
&gt;<br>
&gt; Here&#39;s an example I wrote in my previous email:<br>
&gt; it &quot;should render a 404 when the book is not found&quot; do<br>
&gt; &nbsp;Book.should_receive(:find).with(&quot;1&quot;).and_return nil<br>
&gt; &nbsp;get :show, :id =&gt; &quot;1&quot;<br>
&gt; &nbsp;response.code.should == &quot;404&quot;<br>
&gt; end<br>
&gt;<br>
&gt; Now, I actually wouldn&#39;t write that example. &nbsp;I&#39;d write it as:<br>
&gt; it &quot;should render a 404 when the book is not found&quot; do<br>
&gt; &nbsp;Book.stub!(:find).and_return nil<br>
&gt; &nbsp;get :show, :id =&gt; &quot;1&quot;<br>
&gt; &nbsp;response.code.should == &quot;404&quot;<br>
&gt; end<br>
&gt;<br>
&gt; There&#39;s no reason to set an expectation there, the best way to express<br>
&gt; the intent of that example is to stub it and return nil, indicating<br>
&gt; that we expect different behavior when it&#39;s nil. &nbsp;Anyway, I used<br>
&gt; should_receive in the previous email in case anyone picked up on this<br>
&gt; and discussed that instead instead of the intent of the email.<br>
&gt;<br>
&gt; So this begs the question, in my mind, what happens when you do:<br>
&gt; it &quot;should render a 404 when the book is not found&quot; do<br>
&gt; &nbsp;Book.stub!(:find)<br>
&gt; &nbsp;get :show, :id =&gt; &quot;1&quot;<br>
&gt; &nbsp;response.code.should == &quot;404&quot;<br>
&gt; end<br>
&gt;<br>
&gt; My inclination is that it would work the same as the expectation - it<br>
&gt; would just return the same value as was originally stubbed. &nbsp;The<br>
&gt; difference is that doing this stub would effectively be a noop. &nbsp;Now I<br>
&gt; CAN see the point that you&#39;re re-stubbing this method and it would<br>
&gt; maybe clear out any existing stubs...but again I think it&#39;s a bad idea<br>
&gt; to rely on the reader&#39;s knowledge that stub!, by default, returns nil.<br>
&gt; Then again, it is a tad weird that stub! would set it up to return nil<br>
&gt; in one context, but some different value in another context.<br>
&gt;<br>
&gt; Over all, I think consistency with the expectation API, as well as<br>
&gt; encouraging developers to express intent better in their examples,<br>
&gt; wins out.<br>
&gt;<br>
<br>
</div></div>I&#39;m pretty sure I misread your first email thinking that you wanted to<br>
replace the usage of and_return with reliance on the stubbed out<br>
values from the befores, which I gave a -1 to since I felt that would<br>
provide confusion and lack of clarity. But I don&#39;t think that is at<br>
all what you were suggesting.<br>
<br>
To communicate back to you what I think you&#39;re suggesting... you&#39;d<br>
like to remove unnecessary usages of and_return when it isn&#39;t used to<br>
exemplify the intent of an example. And your argument for principle of<br>
least surprise I do agree with. Not that it matters, but +1.<br>
<br>
Thanks for taking the time to share what you&#39;re thinking more than once. ;)<br>
<div class="Ih2E3d"><br>
<br>
--<br>
Zach Dennis<br>
<a href="http://www.continuousthinking.com" target="_blank">http://www.continuousthinking.com</a><br>
<a href="http://www.mutuallyhuman.com" target="_blank">http://www.mutuallyhuman.com</a><br>
_______________________________________________<br>
</div><div><div></div><div class="Wj3C7c">rspec-devel mailing list<br>
<a href="mailto:rspec-devel@rubyforge.org">rspec-devel@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-devel" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-devel</a><br>
</div></div></blockquote></div><br></div>