[rspec-users] Mocking problem in controller

drewB dbatshaw at gmail.com
Tue Oct 27 11:51:42 EDT 2009


I am having a lot of trouble figure out how to mock one my controller
methods.  I was hoping someone might be able to help me.

---------------

Controller:

  def create
   ....
    @objective = current_user.objectives.create(params[:objective])
   ....
  end

RSpec:

it "should create a new objective and return new id" do
      obj = Objective.plan(:user_id => @user.id)
      post :create, :objective => obj
      response.should be_success
      json = ActiveSupport::JSON.decode(response.body)
      json["id"].should == assigns[:objective].id
end

-----------

As you can see, I am not mocking current_user.objectives.create so I
have to look at assigns[:objective] to test that things are working.
How would I go about mocking it?

Thanks in advance for all your help.


More information about the rspec-users mailing list