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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:12:55+00:00 2026-05-26T09:12:55+00:00

Here is the rspec code for testing show in customers controller: it ‘show’ should

  • 0

Here is the rspec code for testing show in customers controller:

it "'show' should be successful" do
  #category = Factory(:category)
  #sales = Factory(:user)
  #customer = Factory(:customer, :category1_id => category.id, :sales_id => sales.id)
  category = mock_model('Category')
  sales = mock_model('User')
  customer = mock_model(Category, :sales_id => sales.id, :category1_id => category.id)

  get 'show' , :id => customer.id
  response.should be_success
end

Here is the error in rspec:

CustomersController GET customer page 'show' should be successful
     Failure/Error: get 'show' , :id => customer.id
     ActiveRecord::RecordNotFound:
       Couldn't find Customer with id=1003
     # c:in `find'
     # ./app/controllers/customers_controller.rb:59:in `show'
     # ./spec/controllers/customers_controller_spec.rb:50:in `block (3 levels) in <top (required)>'

The rspec test passes with the real record created by Factory (see #ed in rspec code)

What’s wrong with the mock? Thanks.

  • 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-26T09:12:55+00:00Added an answer on May 26, 2026 at 9:12 am

    The spec is failing inside the controller’s action which doesn’t know anything about your mocks unless you told it explicitly.

    Add this to your spec, before the get statement.

    Customer.should_receive(:find).and_return(customer)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the rspec error message: 5) CustomersController GET customer page 'show' should be
Here is the failed rspec code: require 'spec_helper' describe MainMenuController do describe GET 'first_page'
Here is my code, which takes two version identifiers in the form 1, 5,
Here's some simple code that, for each argument specified, will add specific get/set methods
So, I'm trying to learn the rspec BDD testing framework in the context of
Here is the error for update in rspec: 4) CustomersController GET customer page 'update'
I wonder what imperative vs declarative steps in Rspec is all about. Here is
I'm currently testing my mailers with RSpec, but I've started setting up multipart emails
I'm trying to run the basic starter example for using rspec found here: http://rspec.info/
I'm using RSpec + Shoulda to test my RESTful controller in Rails 3. I'm

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.