mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
allow configuring the errors which will be raised by the server
This commit is contained in:
parent
22109e8416
commit
470792ff7f
4 changed files with 26 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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") }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue