简体   繁体   English

为rspec测试rails临时设置Conside_all_requests_local

[英]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. 我有一些我要测试的自定义404和500页面,但我需要暂时将Rails.application.config.consider_all_requests_local设置为false,然后在测试完成后重新打开,以便其他测试可以看到堆栈如果他们在测试过程中失败了。 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. 作为参考,我使用Capybara和selenium-chrome进行测试。

You can set and the reset consider_all_requests_local in before/after blocks: 您可以设置和重置consider_all_requests_local之前/块之后:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 rspec .think_all_requests_local = false 进行测试 - Testing with rspec .consider_all_requests_local = false Rails think_all_requests_local与Rails.env.development是否相对? - Rails consider_all_requests_local vs. if Rails.env.development? Rails 3.2.3最终用户错误消息,而不是在开发模式下使用think_all_requests_local = true的开发人员错误消息 - Rails 3.2.3 End user error messages instead of developer error messages in development mode with consider_all_requests_local = true config / environments / development.rb中“consideration_all_requests_local”的用途? - Purpose of “consider_all_requests_local” in config/environments/development.rb? Ruby on Rails 4-config.consider_all_requests_local =生产环境中为true - Ruby on Rails 4 - config.consider_all_requests_local = true in production 即使config.consider_all_requests_local = false,Heroku也会显示完整的Rails错误页面 - Heroku displaying full Rails error page even though config.consider_all_requests_local = false Rails-使用RSpec设置迁移和测试的默认时间 - Rails - Setting default time in migration and testing with RSpec 在Rspec中测试rails中所有匹配的路由(* path) - testing all matched routes (*path) in rails in Rspec 使用Rspec测试Rails助手:未定义的局部变量或方法`request' - Testing Rails helper with Rspec: undefined local variable or method `request' 在Rails / RSpec请求测试中模拟非本地请求 - Simulating a non-local request in Rails/RSpec request testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM