Skip to content

Commit e10ed1d

Browse files
committed
Fix rubocop warnings
1 parent 9372d2a commit e10ed1d

16 files changed

+59
-53
lines changed

lib/ferrum/browser/process.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def self.process_killer(pid)
4747
end
4848
end
4949
rescue Errno::ESRCH, Errno::ECHILD
50+
# nop
5051
end
5152
end
5253

lib/ferrum/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def dispose
7676
@contexts.dispose(@id)
7777
end
7878

79-
def has_target?(target_id)
79+
def target?(target_id)
8080
!!@targets[target_id]
8181
end
8282

lib/ferrum/contexts.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def default_context
1919

2020
def find_by(target_id:)
2121
context = nil
22-
@contexts.each_value { |c| context = c if c.has_target?(target_id) }
22+
@contexts.each_value { |c| context = c if c.target?(target_id) }
2323
context
2424
end
2525

@@ -68,15 +68,13 @@ def subscribe
6868
end
6969

7070
@browser.client.on("Target.targetDestroyed") do |params|
71-
if context = find_by(target_id: params["targetId"])
72-
context.delete_target(params["targetId"])
73-
end
71+
context = find_by(target_id: params["targetId"])
72+
context&.delete_target(params["targetId"])
7473
end
7574

7675
@browser.client.on("Target.targetCrashed") do |params|
77-
if context = find_by(target_id: params["targetId"])
78-
context.delete_target(params["targetId"])
79-
end
76+
context = find_by(target_id: params["targetId"])
77+
context&.delete_target(params["targetId"])
8078
end
8179
end
8280

lib/ferrum/frame.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ def reset_execution_id
7373
end
7474

7575
def inspect
76-
%(#<#{self.class} @id=#{@id.inspect} @parent_id=#{@parent_id.inspect} @name=#{@name.inspect} @state=#{@state.inspect} @execution_id=#{@execution_id.inspect}>)
76+
"#<#{self.class} "\
77+
"@id=#{@id.inspect} "\
78+
"@parent_id=#{@parent_id.inspect} "\
79+
"@name=#{@name.inspect} "\
80+
"@state=#{@state.inspect} "\
81+
"@execution_id=#{@execution_id.inspect}>"
7782
end
7883
end
7984
end

lib/ferrum/page.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,10 @@ def position
124124
@browser.command("Browser.getWindowBounds", windowId: window_id).fetch("bounds").values_at("left", "top")
125125
end
126126

127-
def position=(*args)
128-
if args.size == 1
129-
left = args[0][:left]
130-
top = args[0][:top]
131-
else
132-
raise "Use like: browser.position = { left: 1, right: 2}"
133-
end
134-
@browser.command("Browser.setWindowBounds", windowId: window_id, bounds: { left: left, top: top })
127+
def position=(options)
128+
@browser.command("Browser.setWindowBounds",
129+
windowId: window_id,
130+
bounds: { left: options[:left], top: options[:top] })
135131
end
136132

137133
def refresh
@@ -279,7 +275,7 @@ def prepare_page
279275

280276
response = command("Page.getNavigationHistory")
281277
if response.dig("entries", 0, "transitionType") != "typed"
282-
# If we create page by clicking links, submiting forms and so on it
278+
# If we create page by clicking links, submitting forms and so on it
283279
# opens a new window for which `frameStoppedLoading` event never
284280
# occurs and thus search for nodes cannot be completed. Here we check
285281
# the history and if the transitionType for example `link` then
@@ -304,13 +300,15 @@ def inject_extensions
304300
def history_navigate(delta:)
305301
history = command("Page.getNavigationHistory")
306302
index, entries = history.values_at("currentIndex", "entries")
303+
entry = entries[index + delta]
307304

308-
if entry = entries[index + delta]
309-
# Potential wait because of network event
310-
command("Page.navigateToHistoryEntry", wait: Mouse::CLICK_WAIT,
311-
slowmoable: true,
312-
entryId: entry["id"])
313-
end
305+
return unless entry
306+
307+
# Potential wait because of network event
308+
command("Page.navigateToHistoryEntry",
309+
wait: Mouse::CLICK_WAIT,
310+
slowmoable: true,
311+
entryId: entry["id"])
314312
end
315313

316314
def combine_url!(url_or_path)

spec/browser_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ module Ferrum
6363

6464
expect do
6565
Browser.new(browser_path: path)
66-
end.to raise_error(Ferrum::ProcessTimeoutError) do |ex|
67-
expect(ex.output).to include "Broken Chrome error message"
66+
end.to raise_error(Ferrum::ProcessTimeoutError) do |e|
67+
expect(e.output).to include "Broken Chrome error message"
6868
end
6969
end
7070

spec/dialog_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ module Ferrum
3838
browser.on(:dialog) do |dialog, _index, _total|
3939
if dialog.match?("Are you sure?")
4040
dialog.accept
41-
elsif dialog.match?("Are you really sure?")
42-
dialog.dismiss
4341
else
4442
dialog.dismiss
4543
end

spec/frame_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ module Ferrum
184184
browser.go_to("/ferrum/frames")
185185
expect(browser.doctype).to eq("<!DOCTYPE html>")
186186

187-
doctype_40 = %(<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">)
188-
browser.set_content(%(#{doctype_40}<html><head></head><body>Voila!</body></html>))
189-
expect(browser.doctype).to eq(doctype_40)
187+
doctype40 = %(<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">)
188+
browser.set_content(%(#{doctype40}<html><head></head><body>Voila!</body></html>))
189+
expect(browser.doctype).to eq(doctype40)
190190

191191
browser.set_content("")
192192
expect(browser.doctype).to be_nil

spec/network/auth_request_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Ferrum
44
class Network
55
describe AuthRequest do
6+
skip
67
end
78
end
89
end

spec/network/intercepted_request_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Ferrum
44
class Network
55
describe InterceptedRequest do
6+
skip
67
end
78
end
89
end

0 commit comments

Comments
 (0)