I'd like to write a spec for testing requests with invalid encoding parameters. The expected behaviour is that the 400 error page is rendered.
module ErrorResponses # See: https://github.com/rails/rails/pull/11289#issuecomment-118612393 def respond_without_detailed_exceptions env_config = Rails.application.env_config original_show_exceptions = env_config["action_dispatch.show_exceptions"] original_show_detailed_exceptions = env_config[ "action_dispatch.show_detailed_exceptions"] env_config["action_dispatch.show_exceptions"] = true env_config["action_dispatch.show_detailed_exceptions"] = false yield ensure env_config["action_dispatch.show_exceptions"] = original_show_exceptions env_config["action_dispatch.show_detailed_exceptions"] = original_show_detailed_exceptions end end RSpec.configure do |config| config.include ErrorResponses end require 'rails_helper' RSpec.describe 'Errors', type: :feature do around :each do |example| respond_without_detailed_exceptions do example.run end end context 'with invalid request parameter' do it 'renders 400' do visit '/home?test=%%aa%%' expect(page.status_code).to eq 400 end end end The problem I'm having is that Rack would throw *Rack::QueryParser::InvalidParameterError* exception when calling *visit '/home?test=%%aa%%'*, and the 400 error is never rendered from the spec. Any help would be appreciated. Thanks. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/27a62e61-b533-4ca3-a362-5a24014afbbd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
