Skip to content

Commit

Permalink
ref: response_expected? -> ping?
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Jan 6, 2024
1 parent b5a5ae8 commit 04a7a41
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `#set_behavior` where and whether to store file
- `Browser::Client#command` accepts :async parameter [#433]
- `Ferrum::Browser` introduce `:flatten` mode with one connection and sessions [#434]
- Support for ping requests [#417]

### Changed
- `Ferrum::Page#screeshot` accepts :area option [#410]
Expand Down
10 changes: 4 additions & 6 deletions lib/ferrum/network/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def blocked?
# @return [Boolean]
#
def finished?
blocked? || response&.loaded? || !error.nil? || !response_expected?
blocked? || response&.loaded? || !error.nil? || ping?
end

#
Expand Down Expand Up @@ -119,14 +119,12 @@ def redirect?
end

#
# Determines if the exchange expects a response
# Determines if the exchange is ping.
#
# @return [Boolean]
#
def response_expected?
return true if request.nil?

!!request.response_expected?
def ping?
!!request&.ping?
end

#
Expand Down
6 changes: 3 additions & 3 deletions lib/ferrum/network/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def time
end

#
# Determines if a response is expected.
# Determines if a request is of type ping.
#
# @return [Boolean]
#
def response_expected?
!type?("ping")
def ping?
type?("ping")
end

#
Expand Down
12 changes: 6 additions & 6 deletions spec/network/exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
exchange = Ferrum::Network::Exchange.new(page, "1")
expect(exchange.finished?).to be false

exchange.request = Ferrum::Network::Request.new({"type" => "Ping"})
exchange.request = Ferrum::Network::Request.new({ "type" => "Ping" })
expect(exchange.finished?).to be true
end
end
Expand All @@ -135,13 +135,13 @@
end
end

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

exchange.request = Ferrum::Network::Request.new({"type" => "Ping"})
expect(exchange.response_expected?).to be false
exchange.request = Ferrum::Network::Request.new({ "type" => "Ping" })
expect(exchange.ping?).to be true
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/network/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

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

expect(request.response_expected?).to be(true)
expect(request.ping?).to be(false)
end

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

expect(request.response_expected?).to be(false)
expect(request.ping?).to be(true)
end
end
end

0 comments on commit 04a7a41

Please sign in to comment.