Skip to content

Commit 2f048df

Browse files
committed
rb - reduce module, class, method, line lengths
1 parent 4d140b5 commit 2f048df

File tree

26 files changed

+307
-322
lines changed

26 files changed

+307
-322
lines changed

rb/.rubocop.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
inherit_from: .rubocop_todo.yml
2-
31
AllCops:
42
TargetRubyVersion: 2.0
53

@@ -20,6 +18,9 @@ Style/PercentLiteralDelimiters:
2018
'%i': '[]'
2119
'%w': '[]'
2220

21+
Style/RegexpLiteral:
22+
EnforcedStyle: mixed
23+
2324
# Consider documenting all top-level classes and modules
2425
Style/Documentation:
2526
Enabled: false
@@ -43,10 +44,43 @@ Style/MutableConstant:
4344
Style/MethodName:
4445
Enabled: false
4546

46-
# Refactor Chrome::Bridge#create_capabilities
47+
# TODO: Refactor Chrome::Bridge#create_capabilities
4748
Metrics/PerceivedComplexity:
48-
Max: 16
49+
Max: 11
50+
Exclude:
51+
- 'lib/selenium/webdriver/chrome/bridge.rb'
4952

50-
# Refactor Chrome::Bridge#create_capabilities
5153
Metrics/CyclomaticComplexity:
52-
Max: 16
54+
Max: 9
55+
Exclude:
56+
- 'lib/selenium/webdriver/chrome/bridge.rb'
57+
- 'lib/selenium/webdriver/common/driver.rb'
58+
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'
59+
60+
Metrics/ClassLength:
61+
Max: 140
62+
Exclude:
63+
- 'lib/selenium/webdriver/firefox/profile.rb'
64+
- 'lib/selenium/webdriver/remote/bridge.rb'
65+
- 'lib/selenium/webdriver/remote/capabilities.rb'
66+
- 'lib/selenium/webdriver/remote/w3c_bridge.rb'
67+
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'
68+
69+
Metrics/AbcSize:
70+
Max: 33
71+
Exclude:
72+
- 'lib/selenium/webdriver/chrome/bridge.rb'
73+
- 'lib/selenium/webdriver/support/color.rb'
74+
75+
Metrics/LineLength:
76+
Max: 130
77+
78+
Metrics/ModuleLength:
79+
Exclude:
80+
- 'lib/selenium/webdriver/common/platform.rb'
81+
- 'spec/**/*'
82+
83+
Metrics/MethodLength:
84+
Max: 33
85+
Exclude:
86+
- 'lib/selenium/webdriver/chrome/bridge.rb'

rb/.rubocop_todo.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

rb/lib/selenium/webdriver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ def self.root
7474
# WebDriver.for :firefox, :profile => Profile.new
7575
# WebDriver.for :remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps
7676
#
77-
# One special argument is not passed on to the bridges, :listener. You can pass a listener for this option
78-
# to get notified of WebDriver events. The passed object must respond to #call or implement the methods from AbstractEventListener.
77+
# One special argument is not passed on to the bridges, :listener.
78+
# You can pass a listener for this option to get notified of WebDriver events.
79+
# The passed object must respond to #call or implement the methods from AbstractEventListener.
7980
#
8081
# @see Selenium::WebDriver::Support::AbstractEventListener
8182
#

rb/lib/selenium/webdriver/chrome.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
module Selenium
2727
module WebDriver
2828
module Chrome
29-
MISSING_TEXT = 'Unable to find the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.'.freeze
29+
MISSING_TEXT = <<-ERROR.tr("\n", '').freeze
30+
Unable to find chromedriver. Please download the server from
31+
http://chromedriver.storage.googleapis.com/index.html and place it
32+
somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
33+
ERROR
3034

3135
def self.driver_path=(path)
3236
Platform.assert_executable path

rb/lib/selenium/webdriver/common/platform.rb

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,40 @@ def home
3232
end
3333

3434
def engine
35-
@engine ||= (
36-
if defined? RUBY_ENGINE
37-
RUBY_ENGINE.to_sym
38-
else
39-
:ruby
40-
end
41-
)
35+
@engine ||= defined?(RUBY_ENGINE) ? RUBY_ENGINE.to_sym : :ruby
4236
end
4337

4438
def os
45-
@os ||= (
46-
host_os = RbConfig::CONFIG['host_os']
47-
case host_os
48-
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
49-
:windows
50-
when /darwin|mac os/
51-
:macosx
52-
when /linux/
53-
:linux
54-
when /solaris|bsd/
55-
:unix
56-
else
57-
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
58-
end
59-
)
39+
host_os = RbConfig::CONFIG['host_os']
40+
@os ||= case host_os
41+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
42+
:windows
43+
when /darwin|mac os/
44+
:macosx
45+
when /linux/
46+
:linux
47+
when /solaris|bsd/
48+
:unix
49+
else
50+
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
51+
end
6052
end
6153

6254
def ci
63-
if ENV['TRAVIS']
64-
:travis
65-
elsif ENV['JENKINS']
66-
:jenkins
67-
end
55+
return :travis if ENV['TRAVIS']
56+
:jenkins if ENV['JENKINS']
6857
end
6958

7059
def bitsize
71-
@bitsize ||= (
72-
if defined?(FFI::Platform::ADDRESS_SIZE)
73-
FFI::Platform::ADDRESS_SIZE
74-
elsif defined?(FFI)
75-
FFI.type_size(:pointer) == 4 ? 32 : 64
76-
elsif jruby?
77-
Integer(ENV_JAVA['sun.arch.data.model'])
78-
else
79-
1.size == 4 ? 32 : 64
80-
end
81-
)
60+
@bitsize ||= if defined?(FFI::Platform::ADDRESS_SIZE)
61+
FFI::Platform::ADDRESS_SIZE
62+
elsif defined?(FFI)
63+
FFI.type_size(:pointer) == 4 ? 32 : 64
64+
elsif jruby?
65+
Integer(ENV_JAVA['sun.arch.data.model'])
66+
else
67+
1.size == 4 ? 32 : 64
68+
end
8269
end
8370

8471
def jruby?
@@ -111,13 +98,11 @@ def cygwin?
11198
end
11299

113100
def null_device
114-
@null_device ||= (
115-
if defined?(File::NULL)
116-
File::NULL
117-
else
118-
Platform.windows? ? 'NUL' : '/dev/null'
119-
end
120-
)
101+
@null_device ||= if defined?(File::NULL)
102+
File::NULL
103+
else
104+
Platform.windows? ? 'NUL' : '/dev/null'
105+
end
121106
end
122107

123108
def wrap_in_quotes_if_necessary(str)
@@ -150,14 +135,11 @@ def assert_executable(path)
150135
def exit_hook
151136
pid = Process.pid
152137

153-
at_exit do
154-
yield if Process.pid == pid
155-
end
138+
at_exit { yield if Process.pid == pid }
156139
end
157140

158141
def find_binary(*binary_names)
159142
paths = ENV['PATH'].split(File::PATH_SEPARATOR)
160-
binary_names.map! { |n| "#{n}.exe" } if windows?
161143

162144
binary_names.each do |binary_name|
163145
paths.each do |path|
@@ -191,11 +173,8 @@ def find_in_program_files(*binary_names)
191173
def localhost
192174
info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM
193175

194-
if info.empty?
195-
raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
196-
end
197-
198-
info[0][3]
176+
return info[0][3] unless info.empty?
177+
raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
199178
end
200179

201180
def ip

rb/lib/selenium/webdriver/edge.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
module Selenium
2626
module WebDriver
2727
module Edge
28-
MISSING_TEXT = 'Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver.'.freeze
28+
MISSING_TEXT = <<-ERROR.tr("\n", '').freeze
29+
Unable to find MicrosoftWebDriver. Please download the server from
30+
https://www.microsoft.com/en-us/download/details.aspx?id=48212 and place it
31+
somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver.
32+
ERROR
2933

3034
def self.driver_path=(path)
3135
Platform.assert_executable path

rb/lib/selenium/webdriver/firefox.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@
3535
module Selenium
3636
module WebDriver
3737
module Firefox
38-
DEFAULT_PORT = 7055
39-
DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows
40-
DEFAULT_SECURE_SSL = false
38+
DEFAULT_PORT = 7055
39+
DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows
40+
DEFAULT_SECURE_SSL = false
4141
DEFAULT_ASSUME_UNTRUSTED_ISSUER = true
42-
DEFAULT_LOAD_NO_FOCUS_LIB = false
42+
DEFAULT_LOAD_NO_FOCUS_LIB = false
4343

44-
MISSING_TEXT = 'Unable to find Mozilla geckodriver. Please download the executable from https://github.com/mozilla/geckodriver/releases'.freeze
44+
MISSING_TEXT = <<-ERROR.tr("\n", '').freeze
45+
Unable to find Mozilla geckodriver. Please download the server from
46+
https://github.com/mozilla/geckodriver/releases and place it
47+
somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.
48+
ERROR
4549

4650
def self.driver_path=(path)
4751
Platform.assert_executable path

rb/lib/selenium/webdriver/firefox/binary.rb

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ module Firefox
2323
# @api private
2424
class Binary
2525
NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'.freeze
26-
NO_FOCUS_LIBRARIES = [
27-
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}", "amd64/#{NO_FOCUS_LIBRARY_NAME}"],
28-
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}", "x86/#{NO_FOCUS_LIBRARY_NAME}"]
26+
NO_FOCUS_LIBRARIES = [
27+
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}",
28+
"amd64/#{NO_FOCUS_LIBRARY_NAME}"],
29+
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}",
30+
"x86/#{NO_FOCUS_LIBRARY_NAME}"]
2931
].freeze
3032

3133
WAIT_TIMEOUT = 90
@@ -38,18 +40,17 @@ def start_with(profile, profile_path, *args)
3840
profile_path = profile_path.tr('/', '\\')
3941
end
4042

41-
ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
42-
ENV['XRE_PROFILE_PATH'] = profile_path
43-
ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
43+
ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
44+
ENV['XRE_PROFILE_PATH'] = profile_path
45+
ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
4446
ENV['MOZ_CRASHREPORTER_DISABLE'] = '1' # disable breakpad
45-
ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
47+
ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
4648

4749
if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
4850
modify_link_library_path profile_path
4951
end
5052

5153
execute(*args)
52-
cope_with_mac_strangeness(args) if Platform.mac?
5354
end
5455

5556
def quit
@@ -80,21 +81,6 @@ def execute(*extra_args)
8081
@process.start
8182
end
8283

83-
def cope_with_mac_strangeness(args)
84-
sleep 0.3
85-
86-
if @process.crashed?
87-
# ok, trying a restart
88-
sleep 7
89-
execute(*args)
90-
end
91-
92-
# ensure we're ok
93-
sleep 0.3
94-
return unless @process.crashed?
95-
raise Error::WebDriverError, "unable to start Firefox cleanly, args: #{args.inspect}"
96-
end
97-
9884
def modify_link_library_path(profile_path)
9985
paths = []
10086

@@ -109,7 +95,7 @@ def modify_link_library_path(profile_path)
10995
paths += ENV['LD_LIBRARY_PATH'].to_s.split(File::PATH_SEPARATOR)
11096

11197
ENV['LD_LIBRARY_PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
112-
ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
98+
ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
11399
end
114100

115101
class << self
@@ -143,7 +129,9 @@ def path
143129
@path = Platform.cygwin_path(@path) if Platform.cygwin?
144130

145131
unless File.file?(@path.to_s)
146-
raise Error::WebDriverError, "Could not find Firefox binary (os=#{Platform.os}). Make sure Firefox is installed or set the path manually with #{self}.path="
132+
error = "Could not find Firefox binary (os=#{Platform.os}). "
133+
error << "Make sure Firefox is installed or set the path manually with #{self}.path="
134+
raise Error::WebDriverError, error
147135
end
148136

149137
@path
@@ -165,7 +153,9 @@ def version
165153
private
166154

167155
def windows_path
168-
windows_registry_path || Platform.find_in_program_files('\\Mozilla Firefox\\firefox.exe') || Platform.find_binary('firefox')
156+
windows_registry_path ||
157+
Platform.find_in_program_files('\\Mozilla Firefox\\firefox.exe') ||
158+
Platform.find_binary('firefox')
169159
end
170160

171161
def macosx_path

rb/lib/selenium/webdriver/firefox/launcher.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def connect_until_stable
8585

8686
return if poller.connected?
8787
@binary.quit
88-
raise Error::WebDriverError, "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
88+
error = "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
89+
raise Error::WebDriverError, error
8990
end
9091

9192
def fetch_profile

rb/lib/selenium/webdriver/firefox/profile.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def initialize(model = nil)
8181
@native_events = model_prefs.delete(WEBDRIVER_PREFS[:native_events]) == 'true'
8282
@secure_ssl = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_certs]) != 'true'
8383
@untrusted_issuer = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_issuer]) == 'true'
84-
@load_no_focus_lib = model_prefs.delete(WEBDRIVER_PREFS[:load_no_focus_lib]) == 'true' # not stored in profile atm, so will always be false.
84+
# not stored in profile atm, so will always be false.
85+
@load_no_focus_lib = model_prefs.delete(WEBDRIVER_PREFS[:load_no_focus_lib]) == 'true'
8586
@additional_prefs = model_prefs
8687
end
8788

0 commit comments

Comments
 (0)