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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:10:57+00:00 2026-06-01T02:10:57+00:00

rspec-rails (2.7.0) rails (3.0.10) post: Rails 3.1 Error Catching is irrelevant for me. Code:

  • 0

rspec-rails (2.7.0) rails (3.0.10)
post: Rails 3.1 Error Catching is irrelevant for me.

Code:

class ApplicationController < ActionController::Base
  unless Rails.application.config.consider_all_requests_local
    rescue_from ActiveRecord::RecordNotFound, :with => :render_404
    rescue_from Exception, :with => :render_500
    rescue_from FunnyException, :with => :my_errors

    def my_errors(exception)
      #some stuff for production
      puts "=======From top====#{Rails.application.config.consider_all_requests_local}"
    end
  else
    rescue_from FunnyException, :with => :my_errors
    def my_errors(exception)
      #some stuff for development
      puts "=====From bottom======#{Rails.application.config.consider_all_requests_local}"
    end
  end
end

This code perfectly works with production/development… problem is when I wanna test it with rspec. How to switch test case between environments?

I tried adding something like:

before do
  Rails.application.config.consider_all_requests_local = true
end

I get:

…=====From bottom======true .=====From bottom======true .=====From
bottom======true .=====From bottom======true

so tried

before do
  Rails.application.config.consider_all_requests_local = false
end

so I get:

…=====From bottom======false .=====From bottom======false .=====From
bottom======false .=====From bottom======false

How is that even possible? … same with changing spec_helper

config.before(:each) do
  Rails.application.config.consider_all_requests_local = false
end

unless is not working. Top section is unreachable with rspec… always hits Bottom why ? I assume it is somehow tied now with Rack… but is there any solution to dynamically change this behavior inside rspec?

regards

  • 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-01T02:10:59+00:00Added an answer on June 1, 2026 at 2:10 am

    Ok I found quite easy solution

    before do
      Rails.application.config.consider_all_requests_local = false
      load "application_controller.rb"
    end
    
    after do
      Rails.application.config.consider_all_requests_local = true
      load "application_controller.rb"
    end
    

    It is part of anonymous application controller test suite.

    You have to add after block… because this change will persist through other suites.

    Any improvements welcome 😀

    edit: Using spork and guard causes for me sometimes random errors… before :all seems to solve that problem

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

Sidebar

Related Questions

I am trying to use rspec on my rails application I run spec path/to/spec/spec.rb
When should I use specs for Rails application and when Cucumber (former rspec-stories)? I
I'm writing an integration test for a rails application using Capybara within Rspec. After
Spoiler: It was an outdated version of the rspec-rails gem! I encountered this error
I am using rspec-rails what's the different between Post.title.should == test and Post.title should
I'd like to take advantage of the force_ssl feature in rails 3.1rc4. class ApplicationController
I'm using RSpec 1 and rspec-rails to test my Rails 2.3.14 application. In this
Rails 3, RSpec 2: In my rspec test for a controller, I'm using post
When dropping the use of rspec and rspec-rails plugins and switching to the gem
I'm not new to Rails or Rspec, but I'm new to making gems. When

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.