Skip to content

Commit 7183715

Browse files
authored
bump and fix rubocop (#158)
* fix rubocop * fix wrong assert * update changelog
1 parent 6b9f74d commit 7183715

36 files changed

+78
-48
lines changed

.rubocop.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Metrics/PerceivedComplexity:
1616
Max: 10
1717
Metrics/ParameterLists:
1818
Max: 6
19+
Lint/NestedMethodDefinition:
20+
Enabled: false
1921
Style/Documentation:
2022
Enabled: false
2123
Style/CommentedKeyword:
@@ -24,9 +26,9 @@ Style/PercentLiteralDelimiters:
2426
Enabled: false
2527
Style/BracesAroundHashParameters:
2628
Enabled: false
27-
Lint/NestedMethodDefinition:
29+
Style/SymbolArray:
2830
Enabled: false
2931
Naming/AccessorMethodName:
3032
Enabled: false
31-
Style/SymbolArray:
33+
Naming/MemoizedInstanceVariableName:
3234
Enabled: false

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Read `release_notes.md` for commit level details.
44

55
## [Unreleased]
66
### Enhancements
7+
- [internal] Update dev libraries
78

89
### Bug fixes
910

appium_lib_core.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'yard', '~> 0.9.11'
3131
spec.add_development_dependency 'minitest', '~> 5.0'
3232
spec.add_development_dependency 'minitest-reporters', '~> 1.1'
33-
spec.add_development_dependency 'webmock', '~> 3.1.0'
34-
spec.add_development_dependency 'rubocop', '0.51.0'
35-
spec.add_development_dependency 'appium_thor', '~> 0.0', '>= 0.0.7'
33+
spec.add_development_dependency 'webmock', '~> 3.4.0'
34+
spec.add_development_dependency 'rubocop', '0.60.0'
35+
spec.add_development_dependency 'appium_thor', '~> 1.0'
3636
spec.add_development_dependency 'pry'
3737
spec.add_development_dependency 'pry-byebug'
3838
spec.add_development_dependency 'parallel_tests'

lib/appium_lib_core.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def self.symbolize_keys(hash)
2020

2121
hash.each_with_object({}) do |pair, acc|
2222
key = begin
23-
pair[0].to_sym
24-
rescue StandardError => e
25-
::Appium::Logger.warn(e.message)
26-
pair[0]
27-
end
23+
pair[0].to_sym
24+
rescue StandardError => e
25+
::Appium::Logger.warn(e.message)
26+
pair[0]
27+
end
2828

2929
value = pair[1]
3030
acc[key] = value.is_a?(Hash) ? symbolize_keys(value) : value

lib/appium_lib_core/android/device.rb

+3
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,13 @@ def toggle_location_services
294294
::Appium::Core::Device.add_endpoint_method(:start_activity) do
295295
def start_activity(opts)
296296
raise 'opts must be a hash' unless opts.is_a? Hash
297+
297298
app_package = opts[:app_package]
298299
raise 'app_package is required' unless app_package
300+
299301
app_activity = opts[:app_activity]
300302
raise 'app_activity is required' unless app_activity
303+
301304
app_wait_package = opts.fetch(:app_wait_package, '')
302305
app_wait_activity = opts.fetch(:app_wait_activity, '')
303306

lib/appium_lib_core/android/device/emulator.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,15 @@ def gsm_voice(state)
135135

136136
::Appium::Core::Device.add_endpoint_method(:set_network_speed) do
137137
def set_network_speed(netspeed)
138-
unless NET_SPEED.member? netspeed.to_sym
139-
raise "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}."
140-
end
138+
raise "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}." unless NET_SPEED.member? netspeed.to_sym
141139

142140
execute(:set_network_speed, {}, { netspeed: netspeed })
143141
end
144142
end
145143

146144
::Appium::Core::Device.add_endpoint_method(:set_power_capacity) do
147145
def set_power_capacity(percent)
148-
unless (0..100).member? percent
149-
raise "The percent should be between 0 and 100. Not #{percent}."
150-
end
146+
raise "The percent should be between 0 and 100. Not #{percent}." unless (0..100).member? percent
151147

152148
execute(:set_power_capacity, {}, { percent: percent })
153149
end

lib/appium_lib_core/android/device/screen.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT'
2424

2525
unless bug_report.nil?
2626
raise 'bug_report should be true or false' unless [true, false].member?(bug_report)
27+
2728
option[:bugReport] = bug_report
2829
end
2930

lib/appium_lib_core/common/base/bridge.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def self.handshake(**opts)
2525
unless ::Selenium::WebDriver::Remote::Capabilities.respond_to?(desired_capabilities)
2626
raise ::Selenium::WebDriver::Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
2727
end
28+
2829
desired_capabilities = ::Selenium::WebDriver::Remote::Capabilities.__send__(desired_capabilities)
2930
end
3031

@@ -105,9 +106,7 @@ def create_session(desired_capabilities)
105106
end
106107
end
107108

108-
unless @session_id
109-
raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload'
110-
end
109+
raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload' unless @session_id
111110

112111
json_create(oss_status, value)
113112
end

lib/appium_lib_core/common/base/search_context.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Base
44
module SearchContext
55
# referenced: ::Selenium::WebDriver::SearchContext
66

7+
# rubocop:disable Layout/AlignHash
78
FINDERS = ::Selenium::WebDriver::SearchContext::FINDERS.merge(
89
accessibility_id: 'accessibility id',
910
image: '-image',
@@ -20,6 +21,7 @@ module SearchContext
2021
# Tizen
2122
tizen_uiautomation: '-tizen uiautomation'
2223
)
24+
# rubocop:enable Layout/AlignHash
2325

2426
#
2527
# Find the first element matching the given arguments
@@ -119,6 +121,7 @@ def find_elements(*args)
119121
def _set_by_from_finders(how)
120122
by = FINDERS[how.to_sym]
121123
raise ArgumentError, "cannot find element by #{how.inspect}. Available finders are #{FINDERS.keys}." unless by
124+
122125
by
123126
end
124127

@@ -129,15 +132,12 @@ def extract_args(args)
129132
when 1
130133
arg = args.first
131134

132-
unless arg.respond_to?(:shift)
133-
raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift"
134-
end
135+
raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift" unless arg.respond_to?(:shift)
135136

136137
# this will be a single-entry hash, so use #shift over #first or #[]
137138
arr = arg.dup.shift
138-
unless arr.size == 2
139-
raise ArgumentError, "expected #{arr.inspect} to have 2 elements"
140-
end
139+
140+
raise ArgumentError, "expected #{arr.inspect} to have 2 elements" unless arr.size == 2
141141

142142
arr
143143
else

lib/appium_lib_core/common/command/common.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# rubocop:disable Layout/AlignHash
12
module Appium
23
module Core
34
# ref: https://github.com/appium/appium-base-driver/blob/master/lib/mjsonwp/routes.js
@@ -87,3 +88,4 @@ module Commands
8788
end # module Commands
8889
end # module Core
8990
end # module Appium
91+
# rubocop:enable Layout/AlignHash

lib/appium_lib_core/common/command/mjsonwp.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# rubocop:disable Layout/AlignHash
12
module Appium
23
module Core
34
module Commands
@@ -12,3 +13,4 @@ module MJSONWP
1213
end # module Commands
1314
end # module Core
1415
end # Appium
16+
# rubocop:enable Layout/AlignHash

lib/appium_lib_core/common/command/w3c.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# rubocop:disable Layout/AlignHash
12
module Appium
23
module Core
34
module Commands
@@ -40,3 +41,4 @@ module W3C
4041
end # module Commands
4142
end # module Core
4243
end # module Appium
44+
# rubocop:enable Layout/AlignHash

lib/appium_lib_core/common/device/image_comparison.rb

+5-9
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ def match_images_features(first_image:,
111111
unless MATCH_FEATURES[:detector_name].member?(detector_name.to_s)
112112
raise "detector_name should be #{MATCH_FEATURES[:detector_name]}"
113113
end
114+
114115
unless MATCH_FEATURES[:match_func].member?(match_func.to_s)
115116
raise "match_func should be #{MATCH_FEATURES[:match_func]}"
116117
end
117-
unless MATCH_FEATURES[:visualize].member?(visualize)
118-
raise "visualize should be #{MATCH_FEATURES[:visualize]}"
119-
end
118+
119+
raise "visualize should be #{MATCH_FEATURES[:visualize]}" unless MATCH_FEATURES[:visualize].member?(visualize)
120120

121121
options = {}
122122
options[:detectorName] = detector_name.to_s.upcase
@@ -128,9 +128,7 @@ def match_images_features(first_image:,
128128
end
129129

130130
def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
131-
unless MATCH_TEMPLATE[:visualize].member?(visualize)
132-
raise "visualize should be #{MATCH_TEMPLATE[:visualize]}"
133-
end
131+
raise "visualize should be #{MATCH_TEMPLATE[:visualize]}" unless MATCH_TEMPLATE[:visualize].member?(visualize)
134132

135133
options = {}
136134
options[:visualize] = visualize
@@ -140,9 +138,7 @@ def find_image_occurrence(full_image:, partial_image:, visualize: false, thresho
140138
end
141139

142140
def get_images_similarity(first_image:, second_image:, visualize: false)
143-
unless GET_SIMILARITY[:visualize].member?(visualize)
144-
raise "visualize should be #{GET_SIMILARITY[:visualize]}"
145-
end
141+
raise "visualize should be #{GET_SIMILARITY[:visualize]}" unless GET_SIMILARITY[:visualize].member?(visualize)
146142

147143
options = {}
148144
options[:visualize] = visualize

lib/appium_lib_core/common/device/screen_record.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def initialize(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_rest
2828
return if force_restart.nil?
2929

3030
raise 'force_restart should be true or false' unless [true, false].member?(force_restart)
31+
3132
@upload_option[:forceRestart] = force_restart
3233
end
3334

lib/appium_lib_core/device.rb

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def add_endpoint_method(method)
4545
# @private CoreBridge
4646
def extend_webdriver_with_forwardable
4747
return if ::Appium::Core::Base::Driver.is_a? Forwardable
48+
4849
::Appium::Core::Base::Driver.class_eval do
4950
extend Forwardable
5051
end
@@ -58,6 +59,7 @@ def delegate_from_appium_driver(method, delegation_target = :driver)
5859

5960
def delegate_driver_method(method)
6061
return if ::Appium::Core::Base::Driver.method_defined? method
62+
6163
::Appium::Core::Base::Driver.class_eval { def_delegator :@bridge, method }
6264
end
6365

lib/appium_lib_core/driver.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ def self.for(opts = {})
132132
new(opts)
133133
end
134134

135+
private
136+
135137
# @private
136138
# For testing purpose of delegate_from_appium_driver
137-
private def delegated_target_for_test
139+
def delegated_target_for_test
138140
@delegate_target
139141
end
140142

143+
public
144+
141145
# @private
142146
def initialize(opts = {})
143147
@delegate_target = self # for testing purpose
@@ -227,7 +231,7 @@ def start_driver(server_url: nil,
227231
private
228232

229233
def create_http_client(http_client: nil, open_timeout: nil, read_timeout: nil)
230-
@http_client ||= http_client ? http_client : Appium::Core::Base::Http::Default.new
234+
@http_client ||= http_client || Appium::Core::Base::Http::Default.new
231235

232236
# open_timeout and read_timeout are explicit wait.
233237
@http_client.open_timeout = open_timeout if open_timeout
@@ -257,7 +261,7 @@ def set_implicit_wait_by_default(wait)
257261
#
258262
def quit_driver
259263
@driver.quit
260-
rescue # rubocop:disable Lint/RescueWithoutErrorClass
264+
rescue # rubocop:disable Style/RescueStandardError
261265
nil
262266
end
263267

@@ -284,6 +288,7 @@ def appium_server_version
284288
@driver.remote_status
285289
rescue Selenium::WebDriver::Error::ServerError => e
286290
raise ::Appium::Core::Error::ServerError unless e.message.include?('status code 500')
291+
287292
# driver.remote_status returns 500 error for using selenium grid
288293
{}
289294
end
@@ -444,6 +449,7 @@ def set_automation_name
444449
# @private
445450
def set_automation_name_if_nil
446451
return unless @automation_name.nil?
452+
447453
@automation_name = if @driver.capabilities['automationName']
448454
@driver.capabilities['automationName'].downcase.strip.intern
449455
end

lib/appium_lib_core/patch.rb

+1
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ def location_rel(driver)
6868
end
6969
end # module Core
7070
end # module Appium
71+
# rubocop:enable Style/ClassAndModuleChildren

script/commands.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_mjsonwp_routes(to_path = './mjsonwp_routes.js')
4040
end
4141

4242
# @private
43-
HTTP_METHOD_MATCH = /GET:|POST:|DELETE:|PUT:|PATCH:/
43+
HTTP_METHOD_MATCH = /GET:|POST:|DELETE:|PUT:|PATCH:/.freeze
4444
# @private
4545
WD_HUB_PREFIX_MATCH = "'/wd/hub/".freeze
4646

test/functional/android/android/device_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,4 @@ def text(value)
425425
end
426426
end
427427
end
428+
# rubocop:enable Style/ClassVars

test/functional/android/android/image_comparison_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ def test_image_comparison_get_images_result
6262
end
6363
end
6464
end
65+
# rubocop:enable Style/ClassVars

test/functional/android/android/search_context_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ def test_uiautomation
2323
end
2424
end
2525
end
26+
# rubocop:enable Style/ClassVars

test/functional/android/driver_test.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_click_back
5050
error = assert_raises ::Selenium::WebDriver::Error::StaleElementReferenceError do
5151
e.click
5252
end
53-
assert error.message 'does not exist'
53+
assert_equal 'does not exist', error.message
5454
@driver.back
5555
end
5656

@@ -76,3 +76,4 @@ def test_mobile_perform_action
7676
# TODO: call @driver.quit after tests
7777
end
7878
end
79+
# rubocop:enable Style/ClassVars

test/functional/android/patch_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ def test_location_rel
4040
end
4141
end
4242
end
43+
# rubocop:enable Style/ClassVars

test/functional/android/webdriver/device_test.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_page_source
6868
xml = REXML::Document.new s_source
6969

7070
assert s_source.include?('io.appium.android.apis')
71-
assert_equal expected, xml[1].elements.each('//*') { |v| v }.map(&:name)
71+
assert_equal expected, xml[1].elements.each('//*') { |v| v }.map(&:name) # rubocop:disable Lint/Void:
7272
end
7373

7474
# def test_location
@@ -146,3 +146,4 @@ def test_session_capability
146146
end
147147
end
148148
end
149+
# rubocop:enable Style/ClassVars

test/functional/android/webdriver/w3c_actions_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,4 @@ def test_multiple_actions
138138
end
139139
end
140140
end
141+
# rubocop:enable Style/ClassVars

test/functional/ios/driver_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ def test_click_back
5656
# TODO: call @driver.quit after tests
5757
end
5858
end
59+
# rubocop:enable Style/ClassVars

test/functional/ios/ios/device_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,4 @@ def test_battery_info
305305
end
306306
end
307307
end
308+
# rubocop:enable Style/ClassVars

test/functional/ios/ios/image_comparison_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ def test_image_comparison_get_images_result
5858
end
5959
end
6060
end
61+
# rubocop:enable Style/ClassVars

test/functional/ios/ios/mjpeg_server_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ def test_config
2424
end
2525
end
2626
end
27+
# rubocop:enable Style/ClassVars

0 commit comments

Comments
 (0)