Skip to content

Commit e4b4426

Browse files
authored
Fix rubocop (#417)
* update rubocop * fix some lint * fix rubocop * add rule into rubocop.yml * add patch version * add template for contributors
1 parent da4ed34 commit e4b4426

File tree

30 files changed

+218
-232
lines changed

30 files changed

+218
-232
lines changed

.rubocop.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Metrics/LineLength:
33
Max: 125
44
Metrics/MethodLength:
55
Enabled: false
6+
Metrics/ModuleLength:
7+
Enabled: false
68
Metrics/ClassLength:
79
Enabled: false
810
Metrics/CyclomaticComplexity:
@@ -11,6 +13,8 @@ Metrics/PerceivedComplexity:
1113
Enabled: false
1214
Metrics/AbcSize:
1315
Enabled: false
16+
Metrics/BlockLength:
17+
Enabled: false
1418
Style/Documentation:
1519
Enabled: false
1620
Style/RegexpLiteral:
@@ -26,3 +30,20 @@ Style/DoubleNegation:
2630
Enabled: false
2731
Style/EachWithObject:
2832
Enabled: false
33+
Style/SpaceAroundOperators:
34+
Enabled: false
35+
Style/ExtraSpacing:
36+
Enabled: false
37+
Style/IndentHash:
38+
Enabled: false
39+
Style/VariableNumber:
40+
EnforcedStyle: 'snake_case'
41+
# The followings should checked again
42+
Style/IdenticalConditionalBranches:
43+
Enabled: false
44+
Lint/NestedMethodDefinition:
45+
Enabled: false
46+
Lint/UnifiedInteger:
47+
Enabled: false
48+
Performance/RedundantBlockCall:
49+
Enabled: false

android_tests/lib/android/specs/android/helper.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,16 @@ def id_value
8585
# api 19
8686
['mFocusedApp=AppWindowToken{b40af858 token=Token{b3e2ce38 ActivityRecord{b3eb47d8 u0 io.appium.android.apis/.ApiDemos t6}}}',
8787
'io.appium.android.apis',
88-
'.ApiDemos'
89-
],
88+
'.ApiDemos'],
9089
# api 16 selendroid
9190
['mFocusedApp=AppWindowToken{4157a2c8 token=Token{41582628 ActivityRecord{415821f0 com.android.launcher/com.android.launcher2.Launcher}}}',
9291
'com.android.launcher',
93-
'com.android.launcher2.Launcher'
94-
]
92+
'com.android.launcher2.Launcher']
9593
]
9694

9795
expected.each do |line, package, activity|
9896
parsed = _parse_current_app_line(line)
99-
fail "failed to parse #{line}" if parsed.nil?
97+
raise "failed to parse #{line}" if parsed.nil?
10098
parsed.package.must_equal package
10199
parsed.activity.must_equal activity
102100
parsed.am_start.must_equal package + '/' + activity

android_tests/lib/android/specs/common/helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
wait(wait_opts) { nil }
1616

1717
# failed wait should error
18-
proc { wait(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError
18+
proc { wait(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError
1919

2020
# regular rescue will not handle exceptions outside of StandardError hierarchy
2121
# must rescue Exception explicitly to rescue everything
22-
proc { wait(wait_opts) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
23-
proc { wait(timeout: 0.2, interval: 0.0) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
22+
proc { wait(wait_opts) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
23+
proc { wait(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
2424

2525
# invalid keys are rejected
2626
proc { wait(invalidkey: 2) { true } }.must_raise RuntimeError
@@ -31,8 +31,8 @@
3131
ignore { true }
3232
ignore { false }
3333
ignore { nil }
34-
ignore { fail }
35-
ignore { fail NoMemoryError }
34+
ignore { raise }
35+
ignore { raise NoMemoryError }
3636
end
3737

3838
# wait_true is a success unless the value is not true
@@ -45,12 +45,12 @@
4545
proc { wait_true(wait_opts) { nil } }.must_raise Selenium::WebDriver::Error::TimeOutError
4646

4747
# raise should error
48-
proc { wait_true(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError
48+
proc { wait_true(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError
4949

5050
# regular rescue will not handle exceptions outside of StandardError hierarchy
5151
# must rescue Exception explicitly to rescue everything
52-
proc { wait_true(wait_opts) { fail NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
53-
proc { wait_true(timeout: 0.2, interval: 0.0) { fail NoMemoryError } }
52+
proc { wait_true(wait_opts) { raise NoMemoryError } }.must_raise Selenium::WebDriver::Error::TimeOutError
53+
proc { wait_true(timeout: 0.2, interval: 0.0) { raise NoMemoryError } }
5454
.must_raise Selenium::WebDriver::Error::TimeOutError
5555

5656
# invalid keys are rejected

android_tests/lib/android/specs/common/web_context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def undo_setcontext_nav
2727

2828
if webview_context.nil?
2929
undo_setcontext_nav
30-
fail "No webview context found. contexts are: #{contexts}"
30+
raise "No webview context found. contexts are: #{contexts}"
3131
end
3232

3333
wait { set_context webview_context }

android_tests/lib/android/specs/driver.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def sauce?
6060
# change :ios in expected to match 'ios' in actual
6161
# [["~", "caps.platformName", :ios, "ios"]]
6262
message = "\n\nactual:\n\n: #{actual.ai}expected:\n\n#{expected.ai}\n\n#{diff}"
63-
fail message
63+
raise message
6464
end
6565

6666
actual_selenium_caps = actual[:caps][:platformName]
@@ -167,7 +167,7 @@ def validate_path(path)
167167
# returns true unless an error is raised
168168
t 'exists' do
169169
exists(0, 0) { true }.must_equal true
170-
exists(0, 0) { fail 'error' }.must_equal false
170+
exists(0, 0) { raise 'error' }.must_equal false
171171
end
172172

173173
# any elements
@@ -189,7 +189,7 @@ def validate_path(path)
189189
begin
190190
set_location latitude: 55, longitude: -72, altitude: 33
191191
rescue Selenium::WebDriver::Error::UnknownError => e
192-
# on android this method is expected to fail with this message when running
192+
# on android this method is expected to raise with this message when running
193193
# on a regular device, or on genymotion.
194194
# error could be many messages, including:
195195
# ERROR running Appium command: port should be a number or string

android_tests/lib/format.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232

3333
indent = 6
3434
puts ' ' * indent + "when '" + tag + "'"
35-
line2 = ' ' * (indent + 2) + "prefix '" + klass + "'"
35+
line_2 = ' ' * (indent + 2) + "prefix '" + klass + "'"
3636
# button must translate to both button and image button
3737
# for ruby_lib to find all buttons
38-
line2 += ", 'ImageButton'" if klass == 'Button'
39-
puts line2
38+
line_2 += ", 'ImageButton'" if klass == 'Button'
39+
puts line_2
4040
end
4141

4242
# for Pry

android_tests/lib/run.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ def start_driver(caps)
1919

2020
# Sanity check
2121
a = OpenStruct.new x: 'ok'
22-
fail 'x issue' unless a.x == 'ok'
22+
raise 'x issue' unless a.x == 'ok'
2323

2424
dir = File.expand_path(File.join(Dir.pwd, 'lib'))
2525
appium_txt = File.join(Dir.pwd, 'appium.txt')
2626
device = ARGV[0].downcase.strip
2727
devices = %w(android selendroid ios)
28-
fail 'Expected android, selendroid or ios as first argument' unless devices.include? device
28+
raise 'Expected android, selendroid or ios as first argument' unless devices.include? device
2929

3030
one_test = ARGV[1]
3131
test_dir = "/#{device}/"
@@ -46,11 +46,12 @@ def start_driver(caps)
4646
one_test = File.join(dir, test_dir + 'specs/', one_test)
4747
end
4848

49-
fail "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)
49+
raise "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)
5050
start_driver(caps)
5151

5252
# require support (common.rb)
53-
Dir.glob(File.join dir, test_dir + '/*.rb') do |test|
53+
file_name = File.join dir, test_dir + '/*.rb'
54+
Dir.glob(file_name) do |test|
5455
require test
5556
trace_files << test
5657
end
@@ -59,7 +60,8 @@ def start_driver(caps)
5960
trace_files << one_test
6061
else
6162
# require all
62-
Dir.glob(File.join dir, test_dir + '**/*.rb') do |test|
63+
file_names = File.join(dir, test_dir + '**/*.rb')
64+
Dir.glob(file_names) do |test|
6365
# load all tests
6466
trace_files << test
6567
puts " #{File.basename(test, '.*')}"

appium_lib.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Gem::Specification.new do |s|
2424
s.add_development_dependency 'spec', '~> 5.3', '>= 5.3.4'
2525
s.add_development_dependency 'fakefs', '~> 0.6.7'
2626

27-
s.add_development_dependency 'rake', '~> 10.4'
27+
s.add_development_dependency 'rake', '~> 12.0'
2828
s.add_development_dependency 'yard', '~> 0.8'
2929

30-
s.add_development_dependency 'rubocop', '~> 0.30.1'
30+
s.add_development_dependency 'rubocop', '~> 0.46.0'
3131

3232
s.files = `git ls-files`.split "\n"
3333
end

contributing.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ Android tests require running on physical hardware with Android 5.0 (API 21). Th
3232
2. Generate release note and create a branch with `rake release`
3333
- Push and merge the branch to the master
3434
3. Build and publish gem with `rake publish`
35+
4. Add release information on GitHub: https://github.com/appium/ruby_lib/releases
36+
- Template
37+
```
38+
1. Enhancements
39+
2. Bug fixes
40+
3. Deprecations
41+
```

ios_tests/lib/common.rb

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -38,91 +38,47 @@ def self.xcuitest?
3838
end
3939

4040
def self.navbar
41-
if xcuitest?
42-
'XCUIElementTypeNavigationBar'
43-
else
44-
'UIANavigationBar'
45-
end
41+
xcuitest? ? 'XCUIElementTypeNavigationBar' : 'UIANavigationBar'
4642
end
4743

4844
def self.button
49-
if xcuitest?
50-
'XCUIElementTypeButton'
51-
else
52-
'UIAButton'
53-
end
45+
xcuitest? ? 'XCUIElementTypeButton' : 'UIAButton'
5446
end
5547

5648
def self.static_text
57-
if xcuitest?
58-
'XCUIElementTypeStaticText'
59-
else
60-
'UIAStaticText'
61-
end
49+
xcuitest? ? 'XCUIElementTypeStaticText' : 'UIAStaticText'
6250
end
6351

6452
def self.text_field
65-
if xcuitest?
66-
'XCUIElementTypeTextField'
67-
else
68-
'UIATextField'
69-
end
53+
xcuitest? ? 'XCUIElementTypeTextField' : 'UIATextField'
7054
end
7155

7256
def self.secure_text_field
73-
if xcuitest?
74-
'XCUIElementTypeSecureTextField'
75-
else
76-
'UIASecureTextField'
77-
end
57+
xcuitest? ? 'XCUIElementTypeSecureTextField' : 'UIASecureTextField'
7858
end
7959

8060
def self.picker
81-
if xcuitest?
82-
'XCUIElementTypePicker'
83-
else
84-
'UIAPicker'
85-
end
61+
xcuitest? ? 'XCUIElementTypePicker' : 'UIAPicker'
8662
end
8763

8864
def self.action_sheet
89-
if xcuitest?
90-
'XCUIElementTypeActionSheet'
91-
else
92-
'UIActionSheet'
93-
end
65+
xcuitest? ? 'XCUIElementTypeActionSheet' : 'UIActionSheet'
9466
end
9567

9668
def self.table
97-
if xcuitest?
98-
'XCUIElementTypeTable'
99-
else
100-
'UIATable'
101-
end
69+
xcuitest? ? 'XCUIElementTypeTable' : 'UIATable'
10270
end
10371

10472
def self.table_cell
105-
if xcuitest?
106-
'XCUIElementTypeCell'
107-
else
108-
'UIATableCell'
109-
end
73+
xcuitest? ? 'XCUIElementTypeCell' : 'UIATableCell'
11074
end
11175

11276
def self.other
113-
if xcuitest?
114-
'XCUIElementTypeOther'
115-
else
116-
fail 'unknown UIA element: other'
117-
end
77+
xcuitest? ? 'XCUIElementTypeOther' : raise('unknown UIA element: other')
11878
end
11979

12080
def self.status_bar
121-
if xcuitest?
122-
'XCUIElementTypeStatusBar'
123-
else
124-
'UIAStatusBar'
125-
end
81+
xcuitest? ? 'XCUIElementTypeStatusBar' : 'UIAStatusBar'
12682
end
12783
end
12884
end

0 commit comments

Comments
 (0)