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 7777865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:15:05+00:00 2026-06-01T18:15:05+00:00

UPDATED: I realise now that I’ve been misreading the diff, and I have a

  • 0

UPDATED: I realise now that I’ve been misreading the diff, and I have a string or symbol on one side of the comparison. Still unsure how I should be putting the expectation in this test however..

I’m new to Rspec and TDD in general, and I’ve run into this problem. I have a controller that does this:

def index
  @users = User.page(params[:page])
end

(I’m using Kaminara to paginate)

And a spec:

describe "when the user DOES have admin status" do

  login_admin_user
  it "should allow the user access to the complete user list page" do
    get :index
    response.response_code.should == 200
  end

  describe "and views the /users page" do
    before(:each) do 
      User.stub(:page) {[ mock_model(User), mock_model(User), mock_model(User) ]}
    end

    it "should show all users" do
    get :index  
    assigns (:users).should =~ User.page
    end
  end

end

The spec fails with the following:

Failure/Error: assigns (:users).should =~ User.page
   expected: [#<User:0x5da86a8 @name="User_1004">, #<User:0x5d9c90c @name="User_1005">, #<User:0x5d93ef6 @name="User_1006">]
        got: :users (using =~)
   Diff:
   @@ -1,4 +1,2 @@
   -[#<User:0x5da86a8 @name="User_1004">,
   - #<User:0x5d9c90c @name="User_1005">,
   - #<User:0x5d93ef6 @name="User_1006">]
   +:users

Those result sets look identical. Why does this spec fail? Thanks in advance!

  • 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-06-01T18:15:06+00:00Added an answer on June 1, 2026 at 6:15 pm

    I think the problem is the space after assigns. It’s comparing the symbol :users to your list. Change it to:

    assigns(:users).should =~ User.page
    

    And just a note on how to read Rspec failures. The part after expected, is what you gave to should, whereas the part after got is the value your code actually produced. So it’s clear from the report that the result sets were not identical.

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

Sidebar

Related Questions

Now I realise this topic has been covered many times before. However there did
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
I've been working with C# and .NET for quite some time now, but am
So you have one list and another. One is used for navigation, the other
I'm trying to ensure that visitors of my ASP.NET MVC website always have the
I have a structure that can be very easily represented using a three-deep nested
I have an application I am making that creates a large number of windows
UPDATED - please read further details below original question I have a select form
I realize this question has been asked many times and I am have looked
i have a login script in that i check if a certain timeperiod has

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.