Skip to content

Commit

Permalink
Update to Ruby 2.3 requirement and fix rubocop warning
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 6, 2019
1 parent ccbc952 commit 511d3cd
Show file tree
Hide file tree
Showing 147 changed files with 235 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _bindings:
if: env(BUILD_ONLY) IS NOT present || env(BUILD_ONLY) =~ /python/
ruby: &ruby
language: ruby
rvm: 2.0.0-p648
rvm: 2.3.8
jdk: oraclejdk8
if: env(BUILD_ONLY) IS NOT present || env(BUILD_ONLY) =~ /ruby/
node: &node
Expand Down
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ shallow_clone: true
build: off
environment:
matrix:
- RUBY_VERSION: 200
- RUBY_VERSION: 23
TASK: build
- RUBY_VERSION: 200
- RUBY_VERSION: 23
TASK: //rb:ie-test
- RUBY_VERSION: 200
- RUBY_VERSION: 23
TASK: //rb:remote-ie-test
- RUBY_VERSION: 200
- RUBY_VERSION: 23
TASK: test_ie
install:
- 'set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0'
- 'set PATH=%JAVA_HOME%;%PATH%'
- 'set RUBY_HOME=C:\Ruby200\bin'
- 'set RUBY_HOME=C:\Ruby23\bin'
- 'set PATH=%RUBY_HOME%;%PATH%'
- 'set BUCK_EXTRA_JAVA_ARGS=-Djna.nosys=true'
before_test:
Expand Down
32 changes: 28 additions & 4 deletions rb/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
AllCops:
TargetRubyVersion: 2.0
TargetRubyVersion: 2.3


Style/FrozenStringLiteralComment:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
Expand Down Expand Up @@ -34,13 +38,25 @@ Naming/FileName:
Exclude:
- 'lib/selenium-webdriver.rb'

Naming/UncommunicativeMethodParamName:
AllowedNames:
- x
- y
- ex
- by
- id
- io

# These need to be fixed
Style/MutableConstant:
Exclude:
- 'lib/selenium/webdriver/common/socket_poller.rb'
- 'lib/selenium/webdriver/remote/legacy_bridge.rb'
- 'lib/selenium/webdriver/remote/w3c_bridge.rb'

Style/CommentedKeyword:
Enabled: false

# TODO: Refactor Chrome::Bridge#create_capabilities
Metrics/PerceivedComplexity:
Max: 11
Expand Down Expand Up @@ -139,7 +155,12 @@ Style/FormatString:
Exclude:
- 'lib/selenium/webdriver/atoms.rb'

Style/MethodMissing:
Style/MethodMissingSuper:
Exclude:
- 'lib/selenium/webdriver/support/event_firing_bridge.rb'
- 'lib/selenium/webdriver/support/block_event_listener.rb'

Style/MissingRespondToMissing:
Exclude:
- 'lib/selenium/webdriver/support/event_firing_bridge.rb'
- 'lib/selenium/webdriver/support/block_event_listener.rb'
Expand Down Expand Up @@ -167,12 +188,15 @@ Style/StringLiterals:
Style/SymbolArray:
Enabled: false

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Style/Dir:
Exclude:
- 'selenium-webdriver.gemspec'

Lint/RescueWithoutErrorClass:
Style/RescueStandardError:
Enabled: false
8 changes: 4 additions & 4 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def download(required_version)
return download_file_name if File.exist? download_file_name

begin
open(download_file_name, 'wb') do |destination|
File.open(download_file_name, 'wb') do |destination|
net_http.start('selenium-release.storage.googleapis.com') do |http|
resp = http.request_get("/#{required_version[/(\d+\.\d+)\./, 1]}/#{download_file_name}") do |response|
total = response.content_length
Expand All @@ -92,9 +92,7 @@ def download(required_version)
end
end

unless resp.is_a? Net::HTTPSuccess
raise Error, "#{resp.code} for #{download_file_name}"
end
raise Error, "#{resp.code} for #{download_file_name}" unless resp.is_a? Net::HTTPSuccess
end
end
rescue
Expand Down Expand Up @@ -255,11 +253,13 @@ def process

def poll_for_service
return if socket.connected?

raise Error, "remote server not launched in #{@timeout} seconds"
end

def poll_for_shutdown
return if socket.closed?

raise Error, "remote server not stopped in #{@timeout} seconds"
end

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module WebDriver
# @api private

def self.root
@root ||= File.expand_path('../..', __FILE__)
@root ||= File.expand_path('..', __dir__)
end

#
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/atoms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read_atom(function)
end

def execute_atom(function_name, *arguments)
script = "return (%s).apply(null, arguments)" % read_atom(function_name)
script = "return (%<atom>s).apply(null, arguments)" % {atom: read_atom(function_name)}
execute_script(script, *arguments)
end

Expand Down
7 changes: 3 additions & 4 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def browser
def quit
super
ensure
@service.stop if @service
@service&.stop
end

def execute_cdp(cmd, **params)
Expand All @@ -76,16 +76,15 @@ def create_capabilities(opts)
if args
WebDriver.logger.deprecate ':args or :switches', 'Selenium::WebDriver::Chrome::Options#add_argument'
raise ArgumentError, ':args must be an Array of Strings' unless args.is_a? Array

args.each { |arg| options.add_argument(arg.to_s) }
end

profile = opts.delete(:profile)
if profile
profile = profile.as_json

if options.args.none? { |arg| arg =~ /user-data-dir/ }
options.add_argument("--user-data-dir=#{profile[:directory]}")
end
options.add_argument("--user-data-dir=#{profile[:directory]}") if options.args.none? { |arg| arg =~ /user-data-dir/ }

if profile[:extensions]
WebDriver.logger.deprecate 'Using Selenium::WebDriver::Chrome::Profile#extensions',
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chrome/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def initialize(**opts)
def add_extension(path)
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'

@extensions << path
end

Expand Down
5 changes: 2 additions & 3 deletions rb/lib/selenium/webdriver/chrome/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def initialize(model = nil)
end

def add_extension(path)
unless File.file?(path)
raise Error::WebDriverError, "could not find extension at #{path.inspect}"
end
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)

@extensions << path
end
Expand Down Expand Up @@ -97,6 +95,7 @@ def prefs

def read_model_prefs
return {} unless @model

JSON.parse File.read(prefs_file_for(@model))
end

Expand Down
11 changes: 6 additions & 5 deletions rb/lib/selenium/webdriver/common/bridge_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def unwrap_script_result(arg)
when Hash
element_id = element_id_from(arg)
return Element.new(self, element_id) if element_id

arg.each { |k, v| arg[k] = unwrap_script_result(v) }
else
arg
Expand All @@ -43,12 +44,12 @@ def element_id_from(id)

def parse_cookie_string(str)
result = {
'name' => '',
'value' => '',
'domain' => '',
'path' => '',
'name' => '',
'value' => '',
'domain' => '',
'path' => '',
'expires' => '',
'secure' => false
'secure' => false
}

str.split(';').each do |attribute|
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 @@ -73,7 +73,7 @@ def initialize(bridge, listener: nil)
end

def inspect
format '#<%s:0x%x browser=%s>', self.class, hash * 2, bridge.browser.inspect
format '#<%<class>s:0x%<hash>x browser=%<browser>s>', class: self.class, hash: hash * 2, browser: bridge.browser.inspect
end

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def location
end

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

@bridge.set_location loc.latitude, loc.longitude, loc.altitude
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def values_to_type
end

def valid_type?(type)
type_to_values.keys.include? type
type_to_values.key? type
end
end # HasNetworkConnection
end # DriverExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ module UploadsFiles
#

def file_detector=(detector)
unless detector.nil? || detector.respond_to?(:call)
raise ArgumentError, 'detector must respond to #call'
end
raise ArgumentError, 'detector must respond to #call' unless detector.nil? || detector.respond_to?(:call)

bridge.file_detector = detector
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 @@ -32,7 +32,7 @@ def initialize(bridge, id)
end

def inspect
format '#<%s:0x%x id=%s>', self.class, hash * 2, @id.inspect
format '#<%<class>s:0x%<hash>x id=%<id>s>', class: self.class, hash: hash * 2, id: @id.inspect
end

def ==(other)
Expand Down
18 changes: 9 additions & 9 deletions rb/lib/selenium/webdriver/common/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ class UnsupportedOperationError < WebDriverError; end
#

ERRORS = {
1 => IndexOutOfBoundsError,
2 => NoCollectionError,
3 => NoStringError,
4 => NoStringLengthError,
5 => NoStringWrapperError,
6 => NoSuchDriverError,
7 => NoSuchElementError,
8 => NoSuchFrameError,
9 => UnknownCommandError,
1 => IndexOutOfBoundsError,
2 => NoCollectionError,
3 => NoStringError,
4 => NoStringLengthError,
5 => NoStringWrapperError,
6 => NoSuchDriverError,
7 => NoSuchElementError,
8 => NoSuchFrameError,
9 => UnknownCommandError,
10 => StaleElementReferenceError,
11 => ElementNotVisibleError,
12 => InvalidElementStateError,
Expand Down
4 changes: 1 addition & 3 deletions rb/lib/selenium/webdriver/common/file_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def <<(file)
def reap(file)
return unless reap?

unless tmp_files.include?(file)
raise Error::WebDriverError, "file not added for reaping: #{file.inspect}"
end
raise Error::WebDriverError, "file not added for reaping: #{file.inspect}" unless tmp_files.include?(file)

FileUtils.rm_rf tmp_files.delete(file)
end
Expand Down
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/common/html5/shared_web_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def key?(key)
def fetch(key)
return self[key] if key? key
return yield(key) if block_given?

raise KeyError, "missing key #{key.inspect}"
end

Expand All @@ -40,7 +41,7 @@ def empty?
def each
return enum_for(:each) unless block_given?

keys.each do |k| # rubocop:disable Performance/HashEachMethods
keys.each do |k|
yield k, self[k]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(name = nil)

def add_action(action)
raise TypeError, "#{action.inspect} is not a valid action" unless action.class < Interaction

@actions << action
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Interaction

def initialize(source)
raise TypeError, "#{source.type} is not a valid input type" unless Interactions::SOURCE_TYPES.include? source.type

@source = source
end
end
Expand Down
2 changes: 2 additions & 0 deletions rb/lib/selenium/webdriver/common/interactions/key_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def type

def encode
return nil if no_actions?

{type: type, id: name, actions: @actions.map(&:encode)}
end

Expand All @@ -49,6 +50,7 @@ def initialize(source, type, key)

def assert_type(type)
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type

KeyInput::SUBTYPES[type]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def type

def encode
return nil if no_actions?

{type: type, id: name, actions: @actions.map(&:encode)}
end
end # NoneInput
Expand Down

0 comments on commit 511d3cd

Please sign in to comment.