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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:00+00:00 2026-06-16T05:26:00+00:00

This is my RSpec test: describe GET #show do it assigns the requested user

  • 0

This is my RSpec test:

describe "GET #show" do
  it "assigns the requested user to @user" do
    user = FactoryGirl.build(:user)
   get :show, id: user
    assigns(:user).should eq(user)
  end
end

This is my rails controller:

  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user }
    end
  end

I get the following error message:

Failures:

  1) UsersController GET #show assigns the requested user to @user
     Failure/Error: get :show, id: user
     ActiveRecord::RecordNotFound:
       Couldn't find User without an ID
     # /home/tim/fairym/app/controllers/users_controller.rb:25:in `show'
     # ./users_controller_spec.rb:21:in `block (3 levels) in <top (required)>'

What is the proper way to use the get method here in order to make the test pass?

  • 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-16T05:26:01+00:00Added an answer on June 16, 2026 at 5:26 am

    You should use FactoryGirl.create and not build. The reason is that create actually makes an entry in the database, including ID. build only makes an object in the memory, without an ID.

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

Sidebar

Related Questions

When running some test with RSpec, I get this error (multiple times): 1) User
I'm trying to do this: How do I test a controller with rspec-rails? My
This following Controller test is failing, and I can't figure out why: describe GET
def mock_category(stubs={}) @mock_category ||= mock_model(Category, stubs).as_null_object end describe GET show do it assigns the
Having trouble framing this assertion in Rspec for my rails app. A User has
I have the following test block in rspec: describe for signed-in users do let(:user)
I'm trying to test my app controller with RSpec on Ruby on Rails. I'm
I have following Rspec test: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user
I get this RSpec error when I try to embed one document in another.
In some Rspec model specs, we have several tests like this: it { should

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.