Hey folks,

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?

I have:

in notes_controller_spec.rb:


before(:each) do
    @mock_note = mock_model(Note, :body => "The hot dog shipment will be in
later tonight.",
                                  :organization => @mock_org)
    @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog Palace",
:notes => [EMAIL PROTECTED])

    @notes = [EMAIL PROTECTED]
  end


it "should render 'notes/new' when the Note is setup with invalid data, i.e.
without a body on POST create" do
      Note.stub!(:new).and_return(@mock_note)
      @notes.stub!(:<<).and_return(false)
      post :create, :organization_id => @mock_org.id, :new_note => { :body
=> @mock_note.body }
      response.should render_template("notes/new")
    end

---

in notes_controller.rb:

def create
    @new_note = Note.new(params[:new_note])

    respond_to do |wants|
      if @organization.notes << @new_note
        wants.html { redirect_to organization_url(@organization) }
      else
        wants.html { render :action => "new" }
      end
    end
  end

I figured that my stubbing the << 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'm not sure why it's not doing so.  I get the error:
expected "notes/new", got nil.  I have code in my Users controller that does
the exact same thing with the << method and the tests pass (they're
virtually identical tests).  Any thoughts?  TIA.


--Tiffani AB
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to