diff --git a/lib/ferrum/errors.rb b/lib/ferrum/errors.rb index 2c46071f..bbd4fcc1 100644 --- a/lib/ferrum/errors.rb +++ b/lib/ferrum/errors.rb @@ -6,7 +6,8 @@ class NoSuchPageError < Error; end class NoSuchTargetError < Error; end class NotImplementedError < Error; end class BinaryNotFoundError < Error; end - class EmptyPathError < Error; end + class EmptyPathError < Error; end + class ServerError < Error; end class StatusError < Error def initialize(url, message = nil) diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 14c38174..8fc9be58 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -40,6 +40,14 @@ ) end end + + it "handles server error" do + expect { page.go_to("/ferrum/server_error") }.not_to raise_error + + expect(page.network.status).to eq(500) + expect(page.network.traffic.last.error.description) + .to eq("Failed to load resource: the server responded with a status of 500 (Internal Server Error)") + end end end diff --git a/spec/support/application.rb b/spec/support/application.rb index 2ad58961..6a8d9cfd 100644 --- a/spec/support/application.rb +++ b/spec/support/application.rb @@ -241,7 +241,7 @@ def requires_credentials(login, password) return if authorized?(login, password) headers["WWW-Authenticate"] = %(Basic realm="Restricted Area") - halt 401, "Not authorized\n" + halt(401, "Not authorized\n") end def authorized?(login, password) @@ -271,7 +271,11 @@ def authorized?(login, password) end get "/ferrum/unexist.png" do - halt 404 + halt(404) + end + + get "/ferrum/server_error" do + halt(500) end get "/ferrum/status/:status" do @@ -329,7 +333,7 @@ def authorized?(login, password) post "/ferrum/ping" do # Sleeping to simulate a server that does not send a response to PING requests sleep 5 - halt 204 + halt(204) end protected