Why consider_all_requests_local fails with rspec config

后端 未结 4 1579
名媛妹妹
名媛妹妹 2021-01-04 12:00

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

Code:

class ApplicationController < ActionController::Base         


        
4条回答
  •  独厮守ぢ
    2021-01-04 12:15

    You also need to set Rails.application.config.action_dispatch.show_exceptions = true. But since Rails caches that value, this will only work if you run your spec on its own. Fortunately, you can change these options only for the current spec by mocking the config:

      before do
        method = Rails.application.method(:env_config)
        expect(Rails.application).to receive(:env_config).with(no_args) do
          method.call.merge(
            "action_dispatch.show_exceptions" => true,
            "action_dispatch.show_detailed_exceptions" => false,
            "consider_all_requests_local" => false
          )
        end
      end
    

    Thanks to:

    • http://atodorov.org/blog/2016/04/27/changing-rails-consider_all_requests_local-in-rspec-fails/
    • https://thepugautomatic.com/2014/08/404-with-rails-4/#comment-1714338343

提交回复
热议问题