In Rails 3.2.9 I have custom error pages defines like this:
# application.rb
config.exceptions_app = self.routes
# routes.rb
match \'/404\' => \'errors#n
With Rails 5.2, Capybara 3 I was able to simulate page errors with the following
around do |example|
Rails.application.config.action_dispatch.show_exceptions = true
example.run
Rails.application.config.action_dispatch.show_exceptions = false
end
before do
allow(Person).to receive(:search).and_raise 'App error simulation!'
end
it 'displays an error message' do
visit root_path
fill_in 'q', with: 'anything'
click_on 'Search'
expect(page).to have_content 'We are sorry, but the application encountered a problem.'
end
This seems to not always work when running the full test suite. So I had to set config.action_dispatch.show_exceptions = true in config/environments/test.rb and remove the around block.