Skip to content

Commit 1754c09

Browse files
committed
chore: Add test to server error
1 parent f188df6 commit 1754c09

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/ferrum/errors.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class NoSuchPageError < Error; end
66
class NoSuchTargetError < Error; end
77
class NotImplementedError < Error; end
88
class BinaryNotFoundError < Error; end
9-
class EmptyPathError < Error; end
9+
class EmptyPathError < Error; end
10+
class ServerError < Error; end
1011

1112
class StatusError < Error
1213
def initialize(url, message = nil)

spec/page_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
)
4141
end
4242
end
43+
44+
it "handles server error" do
45+
expect { page.go_to("/ferrum/server_error") }.not_to raise_error
46+
47+
expect(page.network.status).to eq(500)
48+
expect(page.network.traffic.last.error.description)
49+
.to eq("Failed to load resource: the server responded with a status of 500 (Internal Server Error)")
50+
end
4351
end
4452
end
4553

spec/support/application.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def requires_credentials(login, password)
241241
return if authorized?(login, password)
242242

243243
headers["WWW-Authenticate"] = %(Basic realm="Restricted Area")
244-
halt 401, "Not authorized\n"
244+
halt(401, "Not authorized\n")
245245
end
246246

247247
def authorized?(login, password)
@@ -271,7 +271,11 @@ def authorized?(login, password)
271271
end
272272

273273
get "/ferrum/unexist.png" do
274-
halt 404
274+
halt(404)
275+
end
276+
277+
get "/ferrum/server_error" do
278+
halt(500)
275279
end
276280

277281
get "/ferrum/status/:status" do
@@ -329,7 +333,7 @@ def authorized?(login, password)
329333
post "/ferrum/ping" do
330334
# Sleeping to simulate a server that does not send a response to PING requests
331335
sleep 5
332-
halt 204
336+
halt(204)
333337
end
334338

335339
protected

0 commit comments

Comments
 (0)