Skip to content

fix: rubocop #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ Naming/AccessorMethodName:
Enabled: false
Naming/RescuedExceptionsVariableName:
Enabled: false
Layout/IndentHeredoc:
Layout/HeredocIndentation:
Enabled: false
Layout/RescueEnsureAlignment:
Enabled: false
Layout/HashAlignment:
Enabled: false
Style/ExplicitBlockArgument:
Enabled: false
Style/OptionalBooleanParameter:
Enabled: false
Naming/MethodParameterName:
Enabled: false
Style/KeywordParametersOrder:
Enabled: false
Style/AccessorGrouping:
Enabled: false
Style/StringConcatenation:
Enabled: false
4 changes: 1 addition & 3 deletions android_tests/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ require 'rubocop/rake_task'
task default: :android

# Run sh and ignore exception
# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError
def run_sh(cmd)
sh cmd
rescue
rescue StandardError
# ignored
end
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError

# Run cmd. On failure run install and try again.
def bash(cmd)
Expand Down
4 changes: 2 additions & 2 deletions android_tests/lib/android/specs/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise ::Appium::Core::Wait::TimeoutError

proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
assert_equal'unknown keyword: invalidkey', e.message
assert_equal 'unknown keyword: invalidkey', e.message
end
end

Expand Down Expand Up @@ -69,7 +69,7 @@
.must_raise ::Appium::Core::Wait::TimeoutError

proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
assert_equal'unknown keyword: invalidkey', e.message
assert_equal 'unknown keyword: invalidkey', e.message
end
end

Expand Down
2 changes: 1 addition & 1 deletion android_tests/lib/android/specs/common/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
end

t '::Appium::DATE' do
::Appium::DATE.must_match(/(\d+)\-(\d+)\-(\d+)/)
::Appium::DATE.must_match(/(\d+)-(\d+)-(\d+)/)
end
end
4 changes: 2 additions & 2 deletions android_tests/lib/android/specs/device/touch_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def swipe_till_text_visible(seen_text)
start_x = window_size[:width] / 2
start_y = window_size[:height] / 2
wait(timeout: 0.6) do
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
# Example for Android's log
# [0] pry(#<device/touch_actions>)> swipe start_x: start_x, start_y: start_y, end_x: start_y, end_y: start_y - 100
# [HTTP] --> POST /wd/hub/session/9baa18bf-a19b-4654-be4a-d0db0334bbc0/touch/perform {"actions":[{"action":"press","options":{"x":600,"y":919}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":600,"y":819}},{"action":"release"}]}
Expand All @@ -31,7 +31,7 @@ def swipe_till_text_visible(seen_text)
# [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1200,1838]
# [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Swiping from [x=600.0, y=919.0] to [x=600.0, y=819.0] with steps: 6
# [debug] [AndroidBootstrap] Received command result from bootstrap
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
swipe start_x: start_x, start_y: start_y, end_x: 0.0, end_y: - 100
text(seen_text).displayed?
end
Expand Down
2 changes: 0 additions & 2 deletions android_tests/lib/android/specs/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def sauce?
caps_app_for_teardown = actual[:caps][:app]
expected_app = File.absolute_path('../test_apps/api.apk')

# rubocop:disable Layout/AlignHash
expected = {
automation_name: :uiautomator2,
custom_url: 'http://127.0.0.1:4723/wd/hub',
Expand All @@ -68,7 +67,6 @@ def sauce?
wait_timeout: 30, # default
wait_interval: 0.5 # default
}
# rubocop:enable Layout/AlignHash

# actual[:caps].to_json send to Appium server
caps_with_json = JSON.parse(actual[:caps].to_json)
Expand Down
14 changes: 7 additions & 7 deletions android_tests/lib/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ def start_driver(caps)
else
# ensure ext is .rb
one_test = File.join(File.dirname(one_test),
File.basename(one_test, '.*') + '.rb')
one_test = File.join(dir, test_dir + 'specs/', one_test)
"#{File.basename(one_test, '.*')}.rb")
one_test = File.join(dir, "#{test_dir}specs/#{one_test}")
end

raise "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)

start_driver(caps)

# require support (common.rb)
file_name = File.join dir, test_dir + '/*.rb'
Dir.glob(file_name) do |test|
file_name = File.join dir, "#{test_dir}/*.rb"
Dir.glob(file_name).sort.each do |test|
require test
trace_files << test
end
Expand All @@ -82,8 +82,8 @@ def start_driver(caps)
trace_files << one_test
else
# require all
file_names = File.join(dir, test_dir + '**/*.rb')
Dir.glob(file_names) do |test|
file_names = File.join(dir, "#{test_dir}**/*.rb")
Dir.glob(file_names).sort.each do |test|
# load all tests
trace_files << test
puts " #{File.basename(test, '.*')}"
Expand All @@ -96,7 +96,7 @@ def start_driver(caps)
trace_files.map! do |f|
f = File.expand_path f
# ensure all traced files end in .rb
f = File.join(File.dirname(f), File.basename(f, '.*') + '.rb')
f = File.join(File.dirname(f), "#{File.basename(f, '.*')}.rb")
f
end

Expand Down
2 changes: 1 addition & 1 deletion appium_lib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'posix-spawn', '~> 0.3'
s.add_development_dependency 'pry'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rubocop', '~> 0.68.1'
s.add_development_dependency 'rubocop', '1.6.1'
s.add_development_dependency 'spec', '~> 5.3', '>= 5.3.4'
s.add_development_dependency 'yard', '~> 0.9.11'

Expand Down
5 changes: 2 additions & 3 deletions ios_tests/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ require 'rubocop/rake_task'
task default: :ios

# Run sh and ignore exception
# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError
def run_sh(cmd)
sh cmd
rescue
rescue StandardError
# Ignored
end
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError

# Run cmd. On failure run install and try again.
def bash(cmd)
Expand Down
4 changes: 2 additions & 2 deletions ios_tests/lib/ios/specs/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def before_first
proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise ::Appium::Core::Wait::TimeoutError

proc { wait(invalidkey: 2) { true } }.must_raise ArgumentError do |e|
assert_equal'unknown keyword: invalidkey', e.message
assert_equal 'unknown keyword: invalidkey', e.message
end
end

Expand Down Expand Up @@ -78,7 +78,7 @@ def before_first
.must_raise ::Appium::Core::Wait::TimeoutError

proc { wait_true(invalidkey: 2) { true } }.must_raise ArgumentError do
assert_equal'unknown keyword: invalidkey', e.message
assert_equal 'unknown keyword: invalidkey', e.message
end
end

Expand Down
2 changes: 1 addition & 1 deletion ios_tests/lib/ios/specs/common/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def before_first
end

t '::Appium::DATE' do
::Appium::DATE.must_match(/(\d+)\-(\d+)\-(\d+)/)
::Appium::DATE.must_match(/(\d+)-(\d+)-(\d+)/)
end
end
4 changes: 2 additions & 2 deletions ios_tests/lib/ios/specs/device/touch_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def after_last
size = picker.size.to_h
start_x = loc[:x] + size[:width] / 2
start_y = loc[:y] + size[:height] / 2
# rubocop:disable Metrics/LineLength
# rubocop:disable Layout/LineLength
# Example for iOS's log with XCUITest
# [0] pry(#<device/touch_actions>)> swipe start_x: start_x, start_y: start_y, offset_x: 0, offset_y: - 50
# [debug] [WebDriverAgent] Sim: Jan 14 16:35:05 rrcs-172-254-99-35 CoreSimulatorBridge[65868]: KEYMAP: Chose mode=en_US@hw=Automatic;sw=QWERTY from match=en_US@hw=Automatic;sw=QWERTY from language=en
Expand All @@ -57,7 +57,7 @@ def after_last
# [debug] [UIAuto] Got result from instruments: {"status":0,"value":""}
# [debug] [MJSONWP] Responding to client with driver.performTouch() result: ""
# [HTTP] <-- POST /wd/hub/session/8b651f03-0fbc-43f0-aaf2-243d0650f6aa/touch/perform 200 1895 ms - 74
# rubocop:enable Metrics/LineLength
# rubocop:enable Layout/LineLength
Appium::TouchAction.new.swipe(start_x: start_x, start_y: start_y, end_x: 0, end_y: - 50).perform
ele_index(ui_ios.static_text, 2).text.must_equal 'Chris Armstrong - 0' # depends on iOS
end
Expand Down
2 changes: 0 additions & 2 deletions ios_tests/lib/ios/specs/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def sauce?
caps_app_for_teardown = actual[:caps][:app]
expected_app = File.absolute_path('../test_apps/UICatalog.app.zip')

# rubocop:disable Layout/AlignHash
expected = {
automation_name: :xcuitest,
custom_url: false,
Expand All @@ -67,7 +66,6 @@ def sauce?
wait_timeout: 20, # defined in appium.txt
wait_interval: 1 # defined in appium.txt
}
# rubocop:enable Layout/AlignHash

# actual[:caps].to_json send to Appium server
caps_with_json = JSON.parse(actual[:caps].to_json)
Expand Down
11 changes: 4 additions & 7 deletions ios_tests/lib/ios/specs/ios/element/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# rubocop:disable Lint/HandleExceptions,Style/RescueStandardError

# rake ios['ios/element/text']
describe 'ios/element/text' do
def ui_catalog
Expand Down Expand Up @@ -60,10 +58,10 @@ def before_first
# should fail
set_wait 0
act = begin
text_exact 'mos'
rescue
# nop
end
text_exact 'mos'
rescue StandardError
# nop
end
act.must_be_nil
set_wait

Expand All @@ -75,4 +73,3 @@ def before_first
texts_exact('UICatalog').length.must_equal 1
end
end
# rubocop:enable Lint/HandleExceptions,Style/RescueStandardError
2 changes: 0 additions & 2 deletions ios_tests/lib/ios/specs/ios/element/textfield.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ def after_last
textfields_exact(enter_password).first.value.must_equal enter_password
end

# rubocop:disable Style/DoubleNegation
def keyboard_exists?
!!ignore { wait_true(3) { execute_script 'au.mainApp().keyboard().type() !== "UIAElementNil"' } }
end
# rubocop:enable Style/DoubleNegation

def keyboard_must_not_exist
keyboard_exists?.must_equal false
Expand Down
4 changes: 2 additions & 2 deletions lib/appium_lib/android/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def filter=(value)
@filter = value.to_s.downcase
end

def initialize
def initialize # rubocop:disable Lint/MissingSuper
reset
@filter = false
end
Expand Down Expand Up @@ -217,7 +217,7 @@ def resource_id(string, on_match)
# [^\/]+ - type is made up of at least one non-/ characters
# \\/ - / ends the type and starts the name
# [\S]+$ - the name contains at least one non-space character and then the line is ended
resource_id = /^[a-zA-Z_][a-zA-Z0-9\._]*:[^\/]+\/[\S]+$/
resource_id = /^[a-zA-Z_][a-zA-Z0-9._]*:[^\/]+\/\S+$/
string.match(resource_id) ? on_match : ''
end

Expand Down
7 changes: 3 additions & 4 deletions lib/appium_lib/appium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def load_settings(opts = {})
Appium::Logger.info "Loading #{toml}" if verbose

data = Tomlrb.load_file(toml, symbolize_keys: true)
if verbose
Appium::Logger.info data unless data.empty?
end

Appium::Logger.info data if verbose && !data.empty?

if data && data[:caps] && data[:caps][:app] && !data[:caps][:app].empty?
data[:caps][:app] = Appium::Driver.absolute_app_path data
Expand Down Expand Up @@ -200,7 +199,7 @@ def promote_appium_methods(class_array, driver = $driver)
raise 'Driver is nil' if driver.nil?

# Wrap single class into an array
class_array = [class_array] unless class_array.class == Array
class_array = [class_array] unless class_array.instance_of? Array
# Promote Appium driver methods to class instance methods.
class_array.each do |klass|
driver.public_methods(false).each do |m|
Expand Down
7 changes: 4 additions & 3 deletions lib/appium_lib/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module Common
# Return yield and ignore any exceptions.
def ignore
yield
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
rescue StandardError
# Ignored
end

# Navigate back.
Expand Down Expand Up @@ -73,7 +74,7 @@ def xpaths(xpath_str)
class CountElements < Nokogiri::XML::SAX::Document
attr_reader :result

def initialize(platform)
def initialize(platform) # rubocop:disable Lint/MissingSuper
reset
@platform = platform
end
Expand Down Expand Up @@ -213,7 +214,7 @@ def filter=(value)
@filter = value.to_s.downcase
end

def initialize
def initialize # rubocop:disable Lint/MissingSuper
reset
@filter = false
end
Expand Down
16 changes: 6 additions & 10 deletions lib/appium_lib/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ def set_sauce_related_values(appium_lib_opts)

# Returns a hash of the driver attributes
def driver_attributes
# rubocop:disable Layout/AlignHash
{
caps: @core.caps,
automation_name: @core.automation_name,
Expand All @@ -294,7 +293,6 @@ def driver_attributes
wait_timeout: @core.wait_timeout,
wait_interval: @core.wait_interval
}
# rubocop:enable Layout/AlignHash
end

def device_is_android?
Expand Down Expand Up @@ -425,14 +423,12 @@ def self.absolute_app_path(opts)
return app_path if app_path =~ URI::DEFAULT_PARSER.make_regexp # public URL for Sauce

absolute_app_path = File.expand_path app_path
app_path = if File.exist? absolute_app_path
absolute_app_path
else
::Appium::Logger.info("Use #{app_path}")
app_path
end

app_path
if File.exist? absolute_app_path
absolute_app_path
else
::Appium::Logger.info("Use #{app_path}")
app_path
end
end

# Get the server url
Expand Down
3 changes: 2 additions & 1 deletion lib/appium_lib/ios/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _print_attr(type, name, label, value, hint, visible) # rubocop:disable Metri
puts " visible: #{visible}" if visible
end
end

# iOS only. On Android uiautomator always returns an empty string for EditText password.
#
# Password character returned from value of UIASecureTextField
Expand Down Expand Up @@ -470,7 +471,7 @@ def _by_json(opts)
# will be present.
_validate_object opts[:name], opts[:label], opts[:value]

# note that mainWindow is sometimes nil so it's passed as a param
# NOTE: that mainWindow is sometimes nil so it's passed as a param
# $._elementOrElementsByType will validate that the window isn't nil
element_or_elements_by_type = <<-JS
(function() {
Expand Down
1 change: 0 additions & 1 deletion lib/appium_lib/ios/xcuitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
require_relative 'xcuitest/element'
require_relative 'xcuitest/command'
require_relative 'xcuitest/helper'
require_relative 'xcuitest/element'
require_relative 'xcuitest/bridge'

module Appium
Expand Down
Loading