Skip to content

Commit

Permalink
chore: Add test to server error
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Feb 15, 2024
1 parent f188df6 commit 1754c09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/ferrum/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions spec/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1754c09

Please sign in to comment.