Hey folks,<br><br>I&#39;ve been mocking and stubbing pretty nicely after the various bits of advice I received earlier about doing so.&nbsp; I&#39;ve come to bits of code that work in one place and not in another, though.&nbsp; I&#39;m hoping it&#39;s not something simple I&#39;ve missed.&nbsp; The code below fails even though code that is practically the same elsewhere (except different models in use) passes.&nbsp; What gives?<br>
<br>I have:<br><br>in notes_controller_spec.rb:<br><br><br>before(:each) do<br>&nbsp;&nbsp;&nbsp; @mock_note = mock_model(Note, :body =&gt; &quot;The hot dog shipment will be in later tonight.&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :organization =&gt; @mock_org)<br>
&nbsp;&nbsp;&nbsp; @mock_org = mock_model(Organization, :name =&gt; &quot;Slappy&#39;s Hot Dog Palace&quot;, :notes =&gt; [@mock_note])&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; @notes = [@mock_note]<br>&nbsp; end<br><br><br>it &quot;should render &#39;notes/new&#39; when the Note is setup with invalid data, i.e. without a body on POST create&quot; do<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Note.stub!(:new).and_return(@mock_note)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @notes.stub!(:&lt;&lt;).and_return(false)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post :create, :organization_id =&gt; @<a href="http://mock_org.id">mock_org.id</a>, :new_note =&gt; { :body =&gt; @mock_note.body }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should render_template(&quot;notes/new&quot;)<br>&nbsp;&nbsp;&nbsp; end<br><br>---<br><br>in notes_controller.rb:<br><br>def create<br>&nbsp;&nbsp;&nbsp; @new_note = Note.new(params[:new_note])<br><br>&nbsp;&nbsp;&nbsp; respond_to do |wants|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if @organization.notes &lt;&lt; @new_note<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wants.html { redirect_to organization_url(@organization) }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wants.html { render :action =&gt; &quot;new&quot; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; end<br><br>I figured that my stubbing the &lt;&lt; method out in the test to return false would do the job of triggering the proper branch of the if statement in the controller action, but I&#39;m not sure why it&#39;s not doing so.&nbsp; I get the error: expected &quot;notes/new&quot;, got nil.&nbsp; I have code in my Users controller that does the exact same thing with the &lt;&lt; method and the tests pass (they&#39;re virtually identical tests).&nbsp; Any thoughts?&nbsp; TIA.<br>
<br><br>--Tiffani AB<br>