Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:37:26+00:00 2026-05-22T20:37:26+00:00

I have a controller spec and I get following failed expectation: Failure/Error: put :update,

  • 0

I have a controller spec and I get following failed expectation:

 Failure/Error: put :update, :id => login_user.id, :user => valid_attributes
   #<User:0xbd030bc> received :update_attributes with unexpected arguments
     expected: ({:name=>"changed name", :email=>"changed@mail.com", :password=>"secret", :password_confirmation=>"secret"})
          got: ({"name"=>"Test user", "email"=>"user@test.com", "password"=>"secret", "password_confirmation"=>"secret"})

And for me it looks like I am passing in "name" => "Test User" and I am expecting :name => "test user"

my spec looks like this:

    describe 'with valid parameters' do
      it 'updates the user' do
       login_user = User.create!(valid_attributes)
       controller.stub(:current_user).and_return(login_user)
       User.any_instance.
          should_receive(:update_attributes).
          with(valid_attributes.merge(:email => "changed@mail.com",:name=>"changed name"))
       put :update, :id => login_user.id, :user => valid_attributes
      end 
end

and I have something like this for my valid attributes:

    def valid_attributes
  {
    :name => "Test user",
    :email=> "user@test.com",
    :password => "secret",
    :password_confirmation => "secret"

  }
end

so what is wrong with my parameters any suggestions?

I am using Rails 3.0.5 with rspec 2.6.0…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:37:27+00:00Added an answer on May 22, 2026 at 8:37 pm

    The failure message is telling you exactly what’s going on: any instance of User is expecting update_attributes with a hash including :email => "changed@mail.com", but it’s getting :email => "user@test.com" because that’s what’s in valid_attributes. Similarly, it’s expecting :name => "changed_name", but gets :name => "Test user" because that’s what’s in valid_attributes.

    You can simplify this example and avoid this confusion. There is no need to use valid_attributes here because should_receive intercepts the update_attributes call anyhow. I usually do this like so:

    controller.stub(:current_user).and_return(mock_model(User)) # no need for a real user here
    User.any_instance.
      should_receive(:update_attributes).
      with({"these" => "params"})
    put :update, :id => login_user.id, :user => {"these" => "params"}
    

    This way the expected and actual values are right in the example and it makes clear that it doesn’t really matter what they are: whatever hash is passed in as :user is passed directly to update_attributes.

    Make sense?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple controller actions that takes an id public ActionResult Get(int? id) {
Here is the error for update in rspec: 4) CustomersController GET customer page 'update'
I'm trying to get an RSpec controller spec to pass. It's almost identical to
In my routes.rb i have the following: get 'home/index' root :to => 'home#index' If
I have trying to solve an issue with my Spec tests and I get
I have a spec: it should redirect to the log_books_controller#new action when a user
Here is the failed spec code for create in customer controller: describe CustomersController do
Get the following error when I run autotest. The weird thing is that I
I have a spec for testing a controller as below require 'spec_helper' describe ProductsController
I have controller with action new , and I want it to create ActiveRecord::Base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.