Skip to content

Commit 04a7a41

Browse files
committed
ref: response_expected? -> ping?
1 parent b5a5ae8 commit 04a7a41

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `#set_behavior` where and whether to store file
1010
- `Browser::Client#command` accepts :async parameter [#433]
1111
- `Ferrum::Browser` introduce `:flatten` mode with one connection and sessions [#434]
12+
- Support for ping requests [#417]
1213

1314
### Changed
1415
- `Ferrum::Page#screeshot` accepts :area option [#410]

lib/ferrum/network/exchange.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def blocked?
7979
# @return [Boolean]
8080
#
8181
def finished?
82-
blocked? || response&.loaded? || !error.nil? || !response_expected?
82+
blocked? || response&.loaded? || !error.nil? || ping?
8383
end
8484

8585
#
@@ -119,14 +119,12 @@ def redirect?
119119
end
120120

121121
#
122-
# Determines if the exchange expects a response
122+
# Determines if the exchange is ping.
123123
#
124124
# @return [Boolean]
125125
#
126-
def response_expected?
127-
return true if request.nil?
128-
129-
!!request.response_expected?
126+
def ping?
127+
!!request&.ping?
130128
end
131129

132130
#

lib/ferrum/network/request.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def time
8181
end
8282

8383
#
84-
# Determines if a response is expected.
84+
# Determines if a request is of type ping.
8585
#
8686
# @return [Boolean]
8787
#
88-
def response_expected?
89-
!type?("ping")
88+
def ping?
89+
type?("ping")
9090
end
9191

9292
#

spec/network/exchange_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
exchange = Ferrum::Network::Exchange.new(page, "1")
123123
expect(exchange.finished?).to be false
124124

125-
exchange.request = Ferrum::Network::Request.new({"type" => "Ping"})
125+
exchange.request = Ferrum::Network::Request.new({ "type" => "Ping" })
126126
expect(exchange.finished?).to be true
127127
end
128128
end
@@ -135,13 +135,13 @@
135135
end
136136
end
137137

138-
describe "#response_expected?" do
139-
it "determines if exchange expects a response" do
138+
describe "#ping?" do
139+
it "determines if exchange is ping type" do
140140
exchange = Ferrum::Network::Exchange.new(page, "1")
141-
expect(exchange.response_expected?).to be true
141+
expect(exchange.ping?).to be false
142142

143-
exchange.request = Ferrum::Network::Request.new({"type" => "Ping"})
144-
expect(exchange.response_expected?).to be false
143+
exchange.request = Ferrum::Network::Request.new({ "type" => "Ping" })
144+
expect(exchange.ping?).to be true
145145
end
146146
end
147147

spec/network/request_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# frozen_string_literal: true
22

33
describe Ferrum::Network::Request do
4-
describe "#response_expected?" do
5-
it "returns true for document requests" do
4+
describe "#ping?" do
5+
it "returns false for document requests" do
66
request = Ferrum::Network::Request.new({"type" => "Document"})
77

8-
expect(request.response_expected?).to be(true)
8+
expect(request.ping?).to be(false)
99
end
1010

11-
it "returns false for ping requests" do
11+
it "returns true for ping requests" do
1212
request = Ferrum::Network::Request.new({"type" => "Ping"})
1313

14-
expect(request.response_expected?).to be(false)
14+
expect(request.ping?).to be(true)
1515
end
1616
end
1717
end

0 commit comments

Comments
 (0)