Pat, thanks. That helped. I'm now trying to get my head around the error:<br><br>Spec::Mocks::MockExpectationError in 'AddressesController handling GET /addresses/1 should be successful'<br>Mock 'Address_1006' received unexpected message :find with ("1")
<br><br>My show method in the addresses controller:<br> def show<br> @address = @company.addresses.find(params[:id])<br><br> respond_to do |format|<br> format.html # show.html.erb<br> format.xml { render :xml => @address }
<br> end<br> end<br><br>In the controller spec:<br><br>describe AddressesController, "handling GET /addresses/1" do<br> before do<br> @address = mock_model(Address) <br> @company = mock_model(Company)
<br> <br> Company.stub!(:find_by_id).and_return(@company)<br> @company.stub!(:addresses).and_return(@address)<br> end<br> <br> def do_get<br> get :show, :id => "1", :company_id => "1"
<br> end<br><br> it "should be successful" do<br> do_get<br> response.should be_success<br> end<br><br>....<br><br><br>I know that @company.stub!(:addresses).and_return(@address) is incorrect. I'm trying to work out how I can stub out:
<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> <<a href="mailto:pergesu@gmail.com">
pergesu@gmail.com</a>> 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 <<a href="mailto:pergesu@gmail.com">
pergesu@gmail.com</a>> wrote:<br>> On Nov 21, 2007 1:15 AM, Sahyoun <<a href="mailto:osahyoun@gmail.com">osahyoun@gmail.com</a>> wrote:<br>> > Thanks. That helped. I now have:<br>> ><br>> > before do
<br>> > @address = mock_model(Address)<br>> > @company = mock_model(Company)<br>> > Company.stub!(:find_by_id).and_return(@company)<br>> ><br>> > @company.stub!(:addresses).and_return(@addresses)
<br>> > end<br>> ><br>> ><br>> > with only one error remaining:<br>> ><br>> > 'AddressesController handling GET /addresses should assign the found<br>> > addresses for the view' FAILED
<br>> > expected: [nil],<br>> > got: nil (using ==)<br>> ><br>> > Spec:<br>> > it "should assign the found addresses for the view" do<br>> > do_get<br>> > assigns[:addresses].should == [@addresses]
<br>> > end<br>> ><br>> ><br>> > I thought @company.stub!(:addresses).and_return(@addresses) would be<br>> > sufficient for the above to pass. My understanding of mocking and stubbing<br>
> > is sketchy at the moment. Any explanation on how to get this to pass would<br>> > be appreciated.<br>><br>> @company.stub!(:addresses).and_return([@addresses])<br>><br>> If you're expecting an array, then you need the stub to return an array.
<br>><br>> Pat<br>><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>