Pat, thanks. That helped. I&#39;m now trying to get my head around the error:<br><br>Spec::Mocks::MockExpectationError in &#39;AddressesController handling GET /addresses/1 should be successful&#39;<br>Mock &#39;Address_1006&#39; received unexpected message :find with (&quot;1&quot;)
<br><br>My show method in the addresses controller:<br>&nbsp; def show<br>&nbsp;&nbsp;&nbsp; @address = @company.addresses.find(params[:id])<br><br>&nbsp;&nbsp;&nbsp; respond_to do |format|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; format.html # show.html.erb<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; format.xml&nbsp; { render :xml =&gt; @address }
<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; end<br><br>In the controller spec:<br><br>describe AddressesController, &quot;handling GET /addresses/1&quot; do<br>&nbsp; before do<br>&nbsp;&nbsp;&nbsp; @address = mock_model(Address)&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; @company = mock_model(Company)
<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; Company.stub!(:find_by_id).and_return(@company)<br>&nbsp;&nbsp;&nbsp; @company.stub!(:addresses).and_return(@address)<br>&nbsp; end<br>&nbsp; <br>&nbsp; def do_get<br>&nbsp;&nbsp;&nbsp; get :show, :id =&gt; &quot;1&quot;, :company_id =&gt; &quot;1&quot;
<br>&nbsp; end<br><br>&nbsp; it &quot;should be successful&quot; do<br>&nbsp;&nbsp;&nbsp; do_get<br>&nbsp;&nbsp;&nbsp; response.should be_success<br>&nbsp; end<br><br>....<br><br><br>I know that @company.stub!(:addresses).and_return(@address) is incorrect. I&#39;m trying to work out how I can stub out: &nbsp;&nbsp;&nbsp; 
<br>@address = @company.addresses.find(params[:id])<br><br>Thanks for any pointers.<br><br>Omar<br><br><br><div><span class="gmail_quote">On 21/11/2007, <b class="gmail_sendername">Pat Maddox</b> &lt;<a href="mailto:pergesu@gmail.com">
pergesu@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Nov 21, 2007 1:35 AM, Pat Maddox &lt;<a href="mailto:pergesu@gmail.com">
pergesu@gmail.com</a>&gt; wrote:<br>&gt; On Nov 21, 2007 1:15 AM, Sahyoun &lt;<a href="mailto:osahyoun@gmail.com">osahyoun@gmail.com</a>&gt; wrote:<br>&gt; &gt; Thanks. That helped. I now have:<br>&gt; &gt;<br>&gt; &gt; before do
<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; @address = mock_model(Address)<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; @company = mock_model(Company)<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; Company.stub!(:find_by_id).and_return(@company)<br>&gt; &gt;<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; @company.stub!(:addresses).and_return(@addresses)
<br>&gt; &gt;&nbsp;&nbsp; end<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; with only one error remaining:<br>&gt; &gt;<br>&gt; &gt; &#39;AddressesController handling GET /addresses should assign the found<br>&gt; &gt; addresses for the view&#39; FAILED
<br>&gt; &gt; expected: [nil],<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;got: nil (using ==)<br>&gt; &gt;<br>&gt; &gt;&nbsp;&nbsp;Spec:<br>&gt; &gt;&nbsp;&nbsp; it &quot;should assign the found addresses for the view&quot; do<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; do_get<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; assigns[:addresses].should == [@addresses]
<br>&gt; &gt;&nbsp;&nbsp; end<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; I thought&nbsp;&nbsp;&nbsp;&nbsp; @company.stub!(:addresses).and_return(@addresses) would be<br>&gt; &gt; sufficient for the above to pass. My understanding of mocking and stubbing<br>
&gt; &gt; is sketchy at the moment. Any explanation on how to get this to pass would<br>&gt; &gt; be appreciated.<br>&gt;<br>&gt; @company.stub!(:addresses).and_return([@addresses])<br>&gt;<br>&gt; If you&#39;re expecting an array, then you need the stub to return an array.
<br>&gt;<br>&gt; Pat<br>&gt;<br><br>Guh, sorry, should have looked a bit more closely:<br><br>@company.stub!(:addresses).and_return([@address])<br><br>Pat<br>_______________________________________________<br>rspec-users mailing list
<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br>