简体   繁体   中英

Setting consider_all_requests_local temporarily for rspec testing rails

I have some custom 404 and 500 pages I want to test, but I need Rails.application.config.consider_all_requests_local to be false for feature testing temporarily, and then turn it back on after the test is complete so that other tests can see the stack trace if they fail during testing. Is there any way of doing so or is there possibly another solution to achieve what I'm looking for?

For reference I am using Capybara and selenium-chrome to test.

You can set and the reset consider_all_requests_local in before/after blocks:

describe 'my awesome test' do
  before do
    Rails.application.config.consider_all_requests_local = false
  end

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

  it 'does something magical' do
    # some tests
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM