I'd like to write a feature spec for testing requests with invalid encoding 
parameters. The expected behaviour is to render the 400 page.


```
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?bad_param=%%aa%%' 
      expect(page.status_code).to eq 400 
    end 
  end 
end
```

The problem I'm having is that Rack throws 
`Rack::QueryParser::InvalidParameterError` when calling `visit 
'/home?bad_param=%%aa%%'`, and the 400 error page is never rendered in 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/1f7cd13c-df99-421b-b538-23a7fefc8b83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to