My problem:

Mock 'Task_1005' received unexpected message :user_id= with (1)

No matter what I do to try to stub that out it will still fail out and give
me that message.

Here is my spec


describe TasksController, "handling POST /tasks" do
 before(:each) do
   @task = mock_model(Task, :to_param => "1", :save => true)
   Task.stub!(:new).and_return(@task)
   @user = mock_model(User)
   @user.stub!(:id).and_return(1)
   @user.stub!(:login).and_return("moo")
   User.stub!(:find).and_return(@user)
   @params = {}
 end

 def do_post
   @request.session[:user] = @user.id
   post :create, :task => @params
 end

 it "should create a new task" do
   Task.should_receive(:user_id).with(@user.id).and_return(true)
   Task.should_receive(:new).with(@params).and_return(@task)
   do_post
 end

 it "should redirect to /tasks" do
   Task.should_receive(:user_id).with(@user.id).and_return(true)
   do_post
   response.should redirect_to(home_url)
 end
end

And my controller:

 def create
   @task = Task.new(params[:task])
   @task.user_id = current_user.id
   @task.status = Status.find_by_name('in progress')

   respond_to do |format|
     if @task.save
       flash[:notice] = 'Task was successfully created.'
       format.html { redirect_to home_url }
       format.xml  { head :created, :location => task_url(@task) }
     else
       flash[:error] = @task.errors
       format.html { redirect_to home_url }
       format.xml  { render :xml => @task.errors.to_xml }
     end
   end
 end

So obviously it's failing with the current_user.id thing. I'm using
restful_authentication.

Thanks!
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to