Skip to content

Commit

Permalink
Raise server errors on visit and synchronize
Browse files Browse the repository at this point in the history
This should hopefully make them appear earlier and be more helpful.
  • Loading branch information
jnicklas committed Mar 2, 2014
1 parent 595cd4a commit a94dfbc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/capybara/node/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def synchronize(seconds=Capybara.default_wait_time)
begin
yield
rescue => e
session.raise_server_error!
raise e unless driver.wait?
raise e unless catch_error?(e)
raise e if (Time.now - start_time) >= seconds
Expand Down
14 changes: 12 additions & 2 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,20 @@ def reset!
assert_no_selector :xpath, "/html/body/*"
@touched = false
end
raise_server_error!
end
alias_method :cleanup!, :reset!
alias_method :reset_session!, :reset!

##
#
# Raise errors encountered in the server
#
def raise_server_error!
raise @server.error if Capybara.raise_server_errors and @server and @server.error
ensure
@server.reset_error! if @server
end
alias_method :cleanup!, :reset!
alias_method :reset_session!, :reset!

##
#
Expand Down Expand Up @@ -179,6 +187,8 @@ def title
# @param [String] url The URL to navigate to
#
def visit(url)
raise_server_error!

@touched = true

if url !~ /^http/ and Capybara.app_host
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/click_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
@session.should have_content('Another World')
end

it "raises any errors caught inside the server", :requires => [:server] do
quietly { @session.visit("/error") }
expect do
@session.click_link('foo')
end.to raise_error(TestApp::TestAppError)
end

context "with id given" do
it "should take user to the linked page" do
@session.click_link('foo')
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/visit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
@session.should have_content('Hello world!')
end

it "raises any errors caught inside the server", :requires => [:server] do
quietly { @session.visit("/error") }
expect do
@session.visit("/")
end.to raise_error(TestApp::TestAppError)
end

context "when Capybara.always_include_port is true" do

let(:root_uri) do
Expand Down

0 comments on commit a94dfbc

Please sign in to comment.