Skip to content

Commit

Permalink
rb - update deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 16, 2016
1 parent 9551fe6 commit 8c001ee
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 102 deletions.
30 changes: 2 additions & 28 deletions rb/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-06-09 12:14:10 -0700 using RuboCop version 0.37.2.
# on 2016-06-09 13:11:15 -0700 using RuboCop version 0.37.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'lib/selenium/server.rb'

# Offense count: 10
Lint/HandleExceptions:
Exclude:
Expand Down Expand Up @@ -60,7 +54,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 16

# Offense count: 713
# Offense count: 711
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Expand Down Expand Up @@ -114,13 +108,6 @@ Style/ClassAndModuleChildren:
- 'spec/integration/selenium/webdriver/storage_spec.rb'
- 'spec/integration/selenium/webdriver/touch_spec.rb'

# Offense count: 36
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: is_a?, kind_of?
Style/ClassCheck:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: Keywords.
Expand All @@ -135,19 +122,6 @@ Style/ConstantName:
Exclude:
- 'lib/selenium/webdriver/common/error.rb'

# Offense count: 31
# Cop supports --auto-correct.
Style/DeprecatedHashMethods:
Exclude:
- 'lib/selenium/webdriver/android/bridge.rb'
- 'lib/selenium/webdriver/chrome/bridge.rb'
- 'lib/selenium/webdriver/common/proxy.rb'
- 'lib/selenium/webdriver/edge/bridge.rb'
- 'lib/selenium/webdriver/firefox/profile.rb'
- 'lib/selenium/webdriver/iphone/bridge.rb'
- 'lib/selenium/webdriver/phantomjs/bridge.rb'
- 'lib/selenium/webdriver/remote/capabilities.rb'

# Offense count: 84
Style/Documentation:
Enabled: false
Expand Down
10 changes: 5 additions & 5 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def download(required_version)
required_version = latest if required_version == :latest
download_file_name = "selenium-server-standalone-#{required_version}.jar"

return download_file_name if File.exists? download_file_name
return download_file_name if File.exist? download_file_name

begin
open(download_file_name, "wb") do |destination|
Expand All @@ -94,13 +94,13 @@ def download(required_version)
end
end

unless resp.kind_of? Net::HTTPSuccess
unless resp.is_a? Net::HTTPSuccess
raise Error, "#{resp.code} for #{download_file_name}"
end
end
end
rescue
FileUtils.rm download_file_name if File.exists? download_file_name
FileUtils.rm download_file_name if File.exist? download_file_name
raise
end

Expand Down Expand Up @@ -207,7 +207,7 @@ def webdriver_url
end

def <<(arg)
if arg.kind_of?(Array)
if arg.is_a?(Array)
@additional_args += arg
else
@additional_args << arg.to_s
Expand Down Expand Up @@ -235,7 +235,7 @@ def process
cp = ChildProcess.build("java", "-jar", @jar, "-port", @port.to_s, *@additional_args)
io = cp.io

if @log.kind_of?(String)
if @log.is_a?(String)
@log_file = File.open(@log, "w")
io.stdout = io.stderr = @log_file
elsif @log
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/android/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(opts = {})
desired_capabilities: opts.fetch(:desired_capabilities, capabilities),
}

remote_opts[:http_client] = opts[:http_client] if opts.has_key?(:http_client)
remote_opts[:http_client] = opts[:http_client] if opts.key?(:http_client)

super remote_opts
end
Expand Down
6 changes: 3 additions & 3 deletions rb/lib/selenium/webdriver/chrome/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Bridge < Remote::Bridge
def initialize(opts = {})
http_client = opts.delete(:http_client)

if opts.has_key?(:url)
if opts.key?(:url)
url = opts.delete(:url)
else
@service = Service.new(Chrome.driver_path, Service::DEFAULT_PORT, *extract_service_args(opts))
Expand Down Expand Up @@ -88,7 +88,7 @@ def create_capabilities(opts)
chrome_options = caps['chromeOptions'] || {}

if args
unless args.kind_of? Array
unless args.is_a? Array
raise ArgumentError, ":args must be an Array of Strings"
end

Expand Down Expand Up @@ -124,7 +124,7 @@ def create_capabilities(opts)
def extract_service_args(opts)
args = []

if opts.has_key?(:service_log_path)
if opts.key?(:service_log_path)
args << "--log-path=#{opts.delete(:service_log_path)}"
end

Expand Down
12 changes: 3 additions & 9 deletions rb/lib/selenium/webdriver/common/action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def initialize(mouse, keyboard)
#

def key_down(*args)
if args.first.kind_of? Element
@actions << [:mouse, :click, [args.shift]]
end
@actions << [:mouse, :click, [args.shift]] if args.first.is_a? Element

@actions << [:keyboard, :press, args]
self
Expand All @@ -106,9 +104,7 @@ def key_down(*args)
#

def key_up(*args)
if args.first.kind_of? Element
@actions << [:mouse, :click, [args.shift]]
end
@actions << [:mouse, :click, [args.shift]] if args.first.is_a? Element

@actions << [:keyboard, :release, args]
self
Expand Down Expand Up @@ -136,9 +132,7 @@ def key_up(*args)
#

def send_keys(*args)
if args.first.kind_of? Element
@actions << [:mouse, :click, [args.shift]]
end
@actions << [:mouse, :click, [args.shift]] if args.first.is_a? Element

@actions << [:keyboard, :send_keys, args]
self
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def execute_async_script(script, *args)
#

def [](sel)
sel = {id: sel} if sel.kind_of?(String) || sel.kind_of?(Symbol)
sel = {id: sel} if sel.is_a?(String) || sel.is_a?(Symbol)

find_element sel
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def location
end

def location=(loc)
unless loc.kind_of?(Location)
unless loc.is_a?(Location)
raise TypeError, "expected #{Location}, got #{loc.inspect}:#{loc.class}"
end

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def inspect
end

def ==(other)
other.kind_of?(self.class) && ref == other.ref
other.is_a?(self.class) && ref == other.ref
end
alias_method :eql?, :==

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def self.encode(keys)
when Symbol
Keys[arg]
when Array
arg = arg.map { |e| e.kind_of?(Symbol) ? Keys[e] : e }.join
arg = arg.map { |e| e.is_a?(Symbol) ? Keys[e] : e }.join
arg << Keys[:null]

arg
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/mouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def move_if_needed(element)
end

def assert_element(element)
return if element.kind_of? Element
return if element.is_a? Element
raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
end
end # Mouse
Expand Down
44 changes: 22 additions & 22 deletions rb/lib/selenium/webdriver/common/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ class Proxy
def initialize(opts = {})
opts = opts.dup

self.type = opts.delete(:type) if opts.has_key? :type
self.ftp = opts.delete(:ftp) if opts.has_key? :ftp
self.http = opts.delete(:http) if opts.has_key? :http
self.no_proxy = opts.delete(:no_proxy) if opts.has_key? :no_proxy
self.ssl = opts.delete(:ssl) if opts.has_key? :ssl
self.pac = opts.delete(:pac) if opts.has_key? :pac
self.auto_detect = opts.delete(:auto_detect) if opts.has_key? :auto_detect
self.socks = opts.delete(:socks) if opts.has_key? :socks
self.socks_username = opts.delete(:socks_username) if opts.has_key? :socks_username
self.socks_password = opts.delete(:socks_password) if opts.has_key? :socks_password
self.type = opts.delete(:type) if opts.key? :type
self.ftp = opts.delete(:ftp) if opts.key? :ftp
self.http = opts.delete(:http) if opts.key? :http
self.no_proxy = opts.delete(:no_proxy) if opts.key? :no_proxy
self.ssl = opts.delete(:ssl) if opts.key? :ssl
self.pac = opts.delete(:pac) if opts.key? :pac
self.auto_detect = opts.delete(:auto_detect) if opts.key? :auto_detect
self.socks = opts.delete(:socks) if opts.key? :socks
self.socks_username = opts.delete(:socks_username) if opts.key? :socks_username
self.socks_password = opts.delete(:socks_password) if opts.key? :socks_password

return if opts.empty?
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
end

def ==(other)
other.kind_of?(self.class) && as_json == other.as_json
other.is_a?(self.class) && as_json == other.as_json
end
alias_method :eql?, :==

Expand Down Expand Up @@ -108,7 +108,7 @@ def socks_password=(value)
end

def type=(type)
unless TYPES.has_key? type
unless TYPES.key? type
raise ArgumentError, "invalid proxy type: #{type.inspect}, expected one of #{TYPES.keys.inspect}"
end

Expand Down Expand Up @@ -147,16 +147,16 @@ def json_create(data)

proxy = new

proxy.type = data['proxyType'].downcase.to_sym if data.has_key? 'proxyType'
proxy.ftp = data['ftpProxy'] if data.has_key? 'ftpProxy'
proxy.http = data['httpProxy'] if data.has_key? 'httpProxy'
proxy.no_proxy = data['noProxy'] if data.has_key? 'noProxy'
proxy.pac = data['proxyAutoconfigUrl'] if data.has_key? 'proxyAutoconfigUrl'
proxy.ssl = data['sslProxy'] if data.has_key? 'sslProxy'
proxy.auto_detect = data['autodetect'] if data.has_key? 'autodetect'
proxy.socks = data['socksProxy'] if data.has_key? 'socksProxy'
proxy.socks_username = data['socksUsername'] if data.has_key? 'socksUsername'
proxy.socks_password = data['socksPassword'] if data.has_key? 'socksPassword'
proxy.type = data['proxyType'].downcase.to_sym if data.key? 'proxyType'
proxy.ftp = data['ftpProxy'] if data.key? 'ftpProxy'
proxy.http = data['httpProxy'] if data.key? 'httpProxy'
proxy.no_proxy = data['noProxy'] if data.key? 'noProxy'
proxy.pac = data['proxyAutoconfigUrl'] if data.key? 'proxyAutoconfigUrl'
proxy.ssl = data['sslProxy'] if data.key? 'sslProxy'
proxy.auto_detect = data['autodetect'] if data.key? 'autodetect'
proxy.socks = data['socksProxy'] if data.key? 'socksProxy'
proxy.socks_username = data['socksUsername'] if data.key? 'socksUsername'
proxy.socks_password = data['socksPassword'] if data.key? 'socksPassword'

proxy
end
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/touch_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def coords_from(x, y)
end

def assert_element(element)
return if element.kind_of? Element
return if element.is_a? Element
raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
end
end # TouchScreen
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/edge/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Bridge < Remote::W3CBridge
def initialize(opts = {})
http_client = opts.delete(:http_client)

if opts.has_key?(:url)
if opts.key?(:url)
url = opts.delete(:url)
else
@service = Service.new(Edge.driver_path, Service::DEFAULT_PORT, *extract_service_args(opts))
Expand Down Expand Up @@ -88,7 +88,7 @@ def create_capabilities(opts)
def extract_service_args(opts)
args = []

if opts.has_key?(:service_log_path)
if opts.key?(:service_log_path)
args << "--log-path=#{opts.delete(:service_log_path)}"
end

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/firefox/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(binary, port, profile = nil)

raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1

if profile.kind_of? Profile
if profile.is_a? Profile
@profile = profile
else
@profile_name = profile
Expand Down
8 changes: 4 additions & 4 deletions rb/lib/selenium/webdriver/firefox/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ def layout_on_disk
#

def []=(key, value)
unless VALID_PREFERENCE_TYPES.any? { |e| value.kind_of? e }
unless VALID_PREFERENCE_TYPES.any? { |e| value.is_a? e }
raise TypeError, "expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}"
end

if value.kind_of?(String) && Util.stringified?(value)
if value.is_a?(String) && Util.stringified?(value)
raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}"
end

Expand All @@ -129,7 +129,7 @@ def log_file=(file)
end

def add_webdriver_extension
return if @extensions.has_key?(:webdriver)
return if @extensions.key?(:webdriver)
add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver)
end

Expand Down Expand Up @@ -162,7 +162,7 @@ def assume_untrusted_certificate_issuer=(bool)
end

def proxy=(proxy)
unless proxy.kind_of? Proxy
unless proxy.is_a? Proxy
raise TypeError, "expected #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}"
end

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/iphone/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(opts = {})
desired_capabilities: opts.fetch(:desired_capabilities, capabilities),
}

remote_opts[:http_client] = opts[:http_client] if opts.has_key?(:http_client)
remote_opts[:http_client] = opts[:http_client] if opts.key?(:http_client)

super remote_opts
end
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/phantomjs/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(opts = {})
http_client = opts.delete(:http_client)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.phantomjs }

if opts.has_key?(:url)
if opts.key?(:url)
url = opts.delete(:url)
else
args = opts.delete(:args) || caps['phantomjs.cli.args']
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ def initialize(opts = {})
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
end

if desired_capabilities.kind_of?(Symbol)
if desired_capabilities.is_a?(Symbol)
unless Capabilities.respond_to?(desired_capabilities)
raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
end

desired_capabilities = Capabilities.send(desired_capabilities)
end

uri = url.kind_of?(URI) ? url : URI.parse(url)
uri = url.is_a?(URI) ? url : URI.parse(url)
uri.path += "/" unless uri.path =~ %r{\/$}

http_client.server_url = uri
Expand Down
Loading

0 comments on commit 8c001ee

Please sign in to comment.