Skip to content
Bjørn Trondsen edited this page Oct 17, 2023 · 5 revisions

Modifying middleware at runtime is hard, so if you use gems like capybara and parallel_tests it's probably easiest to just keep the exception handler enabled during boot to get the middleware inserted and then toggle it on off on a test by test basis from Rspec.

config/initializers/rails_exception_handler.rb

RailsExceptionHandler.configure do |config|
  config.environments = %i(production test)
  # ...
end

spec/ rails_helper.rb

RSpec.configure do |config|
  config.before(:each) do |example|
    RailsExceptionHandler.configure do |config|
      config.environments = example.metadata[:enable_rails_exception_handler] ? [:test] : []
      config.storage_strategies = [:rails_log]
      # anything else that needs overriding from initializers/rails_exception_handler.rb
    end
  end
end

spec/request/exception_tracking_spec.rb

require 'rails_helper'
describe 'exception tracking', :enable_rails_exception_handler do
  it "should" do
    # ...
  end
end