Skip to content

Commit 35db994

Browse files
committed
Fix rubocop warnings
1 parent 0c19b9c commit 35db994

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-31
lines changed

lib/capybara/cuprite/browser.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ def window_handles
8181

8282
def within_window(locator = nil)
8383
original = window_handle
84+
raise Ferrum::NoSuchPageError unless window_handles.include?(locator)
8485

85-
if window_handles.include?(locator)
86-
switch_to_window(locator)
87-
yield
88-
else
89-
raise Ferrum::NoSuchPageError
90-
end
86+
switch_to_window(locator)
87+
yield
9188
ensure
9289
switch_to_window(original)
9390
end

lib/capybara/cuprite/driver.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def initialize(app, options = {})
3535
@options[:save_path] = Capybara.save_path.to_s if Capybara.save_path
3636

3737
ENV["FERRUM_DEBUG"] = "true" if ENV["CUPRITE_DEBUG"]
38+
39+
super()
3840
end
3941

4042
def needs_server?
@@ -202,10 +204,9 @@ def clear_network_traffic
202204
browser.network.clear(:traffic)
203205
end
204206

205-
def set_proxy(ip, port, type = nil, user = nil, password = nil, bypass = nil)
207+
def set_proxy(host, port, user = nil, password = nil, bypass = nil)
206208
@options[:browser_options] ||= {}
207-
server = type ? "#{type}=#{ip}:#{port}" : "#{ip}:#{port}"
208-
@options[:browser_options].merge!("proxy-server" => server)
209+
@options[:browser_options].merge!("proxy-server" => "#{host}:#{port}")
209210
@options[:browser_options].merge!("proxy-bypass-list" => bypass) if bypass
210211
browser.network.authorize(type: :proxy, user: user, password: password) do |request, _index, _total|
211212
request.continue

lib/capybara/cuprite/errors.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ClientError < Error
99

1010
def initialize(response)
1111
@response = response
12+
super()
1213
end
1314
end
1415

lib/capybara/cuprite/node.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,15 @@ def scroll_element_to_location(element, location)
257257
end
258258

259259
def scroll_to_location(location)
260-
scroll_y = case location
261-
when :top
262-
"0"
263-
when :bottom
264-
"arguments[0].scrollHeight"
265-
when :center
266-
"(arguments[0].scrollHeight - arguments[0].clientHeight)/2"
267-
end
260+
height = { top: "0",
261+
bottom: "arguments[0].scrollHeight",
262+
center: "(arguments[0].scrollHeight - arguments[0].clientHeight)/2" }
263+
268264
driver.execute_script <<~JS, self
269265
if (arguments[0].scrollTo){
270-
arguments[0].scrollTo(0, #{scroll_y});
266+
arguments[0].scrollTo(0, #{height[location]});
271267
} else {
272-
arguments[0].scrollTop = #{scroll_y};
268+
arguments[0].scrollTop = #{height[location]};
273269
}
274270
JS
275271
end

lib/capybara/cuprite/page.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ def prepare_page
182182
def find_position(node, **options)
183183
node.find_position(**options)
184184
rescue Ferrum::BrowserError => e
185-
if e.message == "Could not compute content quads."
186-
raise MouseEventFailed, "MouseEventFailed: click, none, 0, 0"
187-
else
188-
raise
189-
end
185+
raise MouseEventFailed, "MouseEventFailed: click, none, 0, 0" if e.message == "Could not compute content quads."
186+
187+
raise
190188
end
191189

192190
def active_frame

spec/features/driver_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,12 @@ def create_screenshot(file, *args)
15071507

15081508
it "can return structures with elements" do
15091509
@session.visit("/cuprite/send_keys")
1510-
result = @session.driver.evaluate_script(%({ a: document.getElementById("empty_input"), b: { c: document.querySelectorAll("#empty_textarea, #filled_textarea") } }))
1510+
result = @session.driver.evaluate_script <<~JS
1511+
{
1512+
a: document.getElementById("empty_input"),
1513+
b: { c: document.querySelectorAll("#empty_textarea, #filled_textarea") }
1514+
}
1515+
JS
15111516

15121517
expect(result).to eq(
15131518
"a" => @session.driver.find_css("#empty_input").first,
@@ -1531,7 +1536,9 @@ def create_screenshot(file, *args)
15311536
it "will timeout" do
15321537
@session.using_wait_time(1) do
15331538
expect do
1534-
@session.driver.evaluate_async_script("var callback=arguments[0]; setTimeout(function(){callback(true)}, 4000)")
1539+
@session.driver.evaluate_async_script <<~JS
1540+
var callback=arguments[0]; setTimeout(function(){callback(true)}, 4000)
1541+
JS
15351542
end.to raise_error Ferrum::ScriptTimeoutError
15361543
end
15371544
end

spec/features/session_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@
821821
@session.visit "/"
822822

823823
expect do
824-
@session.within_frame("omg") {}
824+
@session.within_frame("omg", &:itself)
825825
end.to(raise_error do |e|
826826
expect(e).to be_a(Capybara::ElementNotFound)
827827
end)
@@ -917,7 +917,12 @@
917917
context "modals" do
918918
it "accepts by default with warning" do
919919
@session.visit "/cuprite/with_js"
920-
expect(@session.driver.browser.page).to receive(:warn).with("Modal window with text `{T}ext \\w|th [reg.exp] (chara©+er$)?` has been opened, but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` | `dismiss_confirm` | `accept_alert`), accepting by default")
920+
expect(@session.driver.browser.page)
921+
.to receive(:warn).with(
922+
"Modal window with text `{T}ext \\w|th [reg.exp] (chara©+er$)?` has been opened, "\
923+
"but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` "\
924+
"| `dismiss_confirm` | `accept_alert`), accepting by default"
925+
)
921926

922927
expect { @session.click_link("Open for match") }.not_to raise_error
923928

spec/spec_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ module TestSessions
9494

9595
if ENV["CI"] && example.exception
9696
session = @session || TestSessions::Cuprite
97-
save_exception_aftifacts(session.driver.browser, example.metadata)
97+
save_exception_artifacts(session.driver.browser, example.metadata)
9898
end
9999
end
100100

101101
Capybara::SpecHelper.configure(config)
102102

103-
def save_exception_aftifacts(browser, meta)
103+
def save_exception_artifacts(browser, meta)
104104
time_now = Time.now
105105
filename = File.basename(meta[:file_path])
106106
line_number = meta[:line_number]
107-
timestamp = "#{time_now.strftime('%Y-%m-%d-%H-%M-%S.')}#{'%03d' % (time_now.usec / 1000).to_i}"
107+
timestamp = time_now.strftime("%Y-%m-%d-%H-%M-%S.") + format("%03d", (time_now.usec / 1000).to_i)
108108

109109
save_exception_log(browser, filename, line_number, timestamp)
110110
save_exception_screenshot(browser, filename, line_number, timestamp)

0 commit comments

Comments
 (0)