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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:35:48+00:00 2026-05-14T08:35:48+00:00

Within my controller specs I am stubbing out valid? for some routing tests, (based

  • 0

Within my controller specs I am stubbing out valid? for some routing tests, (based on Ryan Bates nifty_scaffold) as follows :-

it "create action should render new template when model is invalid" do
  Company.any_instance.stubs(:valid?).returns(false)
  post :create
  response.should render_template(:new)
end

This is fine when I test the controllers in isolation. I also have the following in my model spec

it "is valid with valid attributes" do
  @company.should be_valid
end

Again this works fine when tested in isolation. The problem comes if I run spec for both models and controllers. The model test always fails as the valid? method has been stubbed out. Is there a way for me to remove the stubbing of any_instance when the controller test is torn down.

I have got around the problem by running the tests in reverse alphabetic sequence to ensure the model tests run before the controllers but I really don’t like my tests being sequence dependant.

  • 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-14T08:35:48+00:00Added an answer on May 14, 2026 at 8:35 am

    You need to manually configure RSpec.

    Rspec.configure do |config|
      ...
    
      # == Mock Framework
      #
      # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
      #
      config.mock_with :mocha
      # config.mock_with :flexmock
      # config.mock_with :rr
      # config.mock_with :rspec
    end
    

    Also, remember that Rspec provides its own methods to mock an object. Use the RSpec API or you won’t be able to benefit from library abstraction.
    http://rspec.info/documentation/mocks/message_expectations.html

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

Sidebar

Related Questions

When you call RedirectToAction within a controller, it automatically redirects using an HTTP GET.
Within an application, I've got Secret Keys uses to calculate a hash for an
Within Ruby on Rails applications database.yml is a plain text file that stores database
Within c#, I need to be able to Connect to a remote system, specifying
Within SQL Server Integration Services (SSIS) there is the ability to setup a connection
Within our Active Directory domain, we have a MS SQL 2005 server, and a
Within your organization, is every developer required to lock his workstation when leaving it?
Within a stored procedure, another stored procedure is being called within a cursor. For
Within my Subversion project I have a few directories that contain other open source
Within an n-tier app that makes use of a WCF service to interact with

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.