diff --git a/lib/capybara.rb b/lib/capybara.rb index 1f43e6c3..b83110b5 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -22,7 +22,7 @@ module Capybara attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements - attr_accessor :save_and_open_page_path, :automatic_reload, :raise_server_errors + attr_accessor :save_and_open_page_path, :automatic_reload, :raise_server_errors, :server_errors attr_writer :default_driver, :current_driver, :javascript_driver, :session_name, :server_host attr_accessor :app @@ -135,7 +135,7 @@ module Capybara ## # # Wraps the given string, which should contain an HTML document or fragment - # in a {Capybara::Node::Simple} which exposes all {Capybara::Node::Matchers}, + # in a {Capybara::Node::Simple} which exposes all {Capybara::Node::Matchers}, # {Capybara::Node::Finders} and {Capybara::Node::DocumentMatchers}. This allows you to query # any string containing HTML in the exact same way you would query the current document in a Capybara # session. For example: @@ -365,6 +365,7 @@ Capybara.configure do |config| config.match = :smart config.exact = false config.raise_server_errors = true + config.server_errors = [StandardError] config.visible_text_only = false end diff --git a/lib/capybara/server.rb b/lib/capybara/server.rb index dc993a6f..28df7bc6 100644 --- a/lib/capybara/server.rb +++ b/lib/capybara/server.rb @@ -17,7 +17,7 @@ module Capybara else begin @app.call(env) - rescue StandardError => e + rescue *Capybara.server_errors => e @error = e unless @error raise e end diff --git a/lib/capybara/spec/session/reset_session_spec.rb b/lib/capybara/spec/session/reset_session_spec.rb index ca26bf1e..d2704acf 100644 --- a/lib/capybara/spec/session/reset_session_spec.rb +++ b/lib/capybara/spec/session/reset_session_spec.rb @@ -37,7 +37,7 @@ Capybara::SpecHelper.spec '#reset_session!' do expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false end - it "raises any errors caught inside the server", :requires => [:server] do + it "raises any standard errors caught inside the server", :requires => [:server] do quietly { @session.visit("/error") } expect do @session.reset_session! @@ -46,6 +46,23 @@ Capybara::SpecHelper.spec '#reset_session!' do expect(@session.current_path).to eq("/") end + it "raises configured errors caught inside the server", :requires => [:server] do + prev_errors = Capybara.server_errors + + Capybara.server_errors = [LoadError] + quietly { @session.visit("/error") } + expect do + @session.reset_session! + end.not_to raise_error + + quietly { @session.visit("/load_error") } + expect do + @session.reset_session! + end.to raise_error(LoadError) + + Capybara.server_errors = prev_errors + end + it "ignores server errors when `Capybara.raise_server_errors = false`", :requires => [:server] do Capybara.raise_server_errors = false quietly { @session.visit("/error") } diff --git a/lib/capybara/spec/test_app.rb b/lib/capybara/spec/test_app.rb index 4c2df3f0..5d62f455 100644 --- a/lib/capybara/spec/test_app.rb +++ b/lib/capybara/spec/test_app.rb @@ -123,6 +123,10 @@ class TestApp < Sinatra::Base raise TestAppError, "some error" end + get '/load_error' do + raise LoadError + end + get '/:view' do |view| erb view.to_sym end