<br><div class="gmail_quote">On Mon, Jul 7, 2008 at 5:55 PM, Britt Mileshosky <<a href="mailto:mileshosky@hotmail.com">mileshosky@hotmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
________________________________<br>
> Date: Mon, 7 Jul 2008 17:27:36 -0400<br>
> From: <a href="mailto:tiffani2k3@gmail.com">tiffani2k3@gmail.com</a><br>
> To: <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
> Subject: [rspec-users] Not sure why this controller spec isn't working<br>
<div class="Ih2E3d">><br>
> Hey folks,<br>
><br>
> I've been mocking and stubbing pretty nicely after the various bits of advice I received earlier about doing so. I've come to bits of code that work in one place and not in another, though. I'm hoping it's not something simple I've missed. The code below fails even though code that is practically the same elsewhere (except different models in use) passes. What gives?<br>
><br>
> I have:<br>
><br>
> in notes_controller_spec.rb:<br>
><br>
><br>
> before(:each) do<br>
> @mock_note = mock_model(Note, :body => "The hot dog shipment will be in later tonight.",<br>
> :organization => @mock_org)<br>
> @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog Palace", :notes => [@mock_note])<br>
><br>
> @notes = [@mock_note]<br>
> end<br>
><br>
><br>
> it "should render 'notes/new' when the Note is setup with invalid data, i.e. without a body on POST create" do<br>
> Note.stub!(:new).and_return(@mock_note)<br>
</div>> @notes.stub!(:< post :create, :organization_id => @<a href="http://mock_org.id" target="_blank">mock_org.id</a>, :new_note => { :body => @mock_note.body }<br>
<div class="Ih2E3d">> response.should render_template("notes/new")<br>
> end<br>
></div></blockquote><div><br>To add to what Britt already said, look at your example and then your before block again very carefully. Notice that you setup @notes in your before, and you use it to stub :<< in your example, but you never return @notes from anything. Instead you setup @mock_org to return an array with @mock_note. Although the contents of this and @notes are the same, you have created two different arrays. You are probably wanting to be dealing with the same @notes object in each of these cases.<br>
<br>Zach<br></div></div><br clear="all"><br>-- <br>Zach Dennis<br><a href="http://www.continuousthinking.com">http://www.continuousthinking.com</a>