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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:46:34+00:00 2026-05-16T16:46:34+00:00

def mock_category(stubs={}) @mock_category ||= mock_model(Category, stubs).as_null_object end describe GET show do it assigns the

  • 0
def mock_category(stubs={})
  @mock_category ||= mock_model(Category, stubs).as_null_object
end

describe "GET show" do
  it "assigns the requested category as @category" do
    Category.stub(:find).with("37") { mock_category }
    get :show, :id => "37"
    assigns(:category).should be(mock_category)
  end
end

Which returns :

1) CategoriesController GET show assigns the requested category as @category
   Failure/Error: assigns(:category).should be(mock_category)
   expected Category_1002, got nil

I’m confused here, because this is a right out of the box controller that rspec set up. Why could this be failing?

My versions:

Rails 3.0.0.beta4
Ruby 1.8.7
RSpec 2.0.0.beta.10

Also tried this, same exact reproducible error with :

Rails 3.0.0
Ruby 1.8.7
RSpec 2.0.0.beta.20

The command I used to generate the specs were rails g scaffold Category

In my application.rb

config.generators do |g|
  g.template_engine :haml
  g.test_framework :rspec, :fixture => true, :views => false
end

UPDATE

This goes for any scaffolded controller by Rails 3, with RSpec2. Its guarenteed to fail. Anyone know how this is supposed to be written?

  • 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-16T16:46:34+00:00Added an answer on May 16, 2026 at 4:46 pm

    The conflict comes from conflicts that occurred between Rspec Beta 10 and Rspec Beta 20, and Rails 3 Beta4, to Rails 3 release.

    To solve this, I uninstalled haml, and installed haml-rails.

    Then I deleted all the specs that were previously generated, and regenerated them.

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

Sidebar

Related Questions

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
i have some action in my rails application def show @issue = Issue.find(params[:id], :include
I'm trying to run the following spec: describe UsersController, GET friends do it should
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
I have a TopicsController , with new action: def new @section = Section.find(params[:section_id]) @topic
How would I test the following finder with RSpec? def self.find_by_mbid(mbid) super(mbid.downcase()) end The
How should I spec this class FlagsController def like flag = current_user.flags.find_or_initialize_by_flaggable_type_and_flaggable_id(params[:like_type], params[:like_id]) flag.kind
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then

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.