Skip to content

Commit

Permalink
Fix rubocop (#417)
Browse files Browse the repository at this point in the history
* update rubocop

* fix some lint

* fix rubocop

* add rule into rubocop.yml

* add patch version

* add template for contributors
  • Loading branch information
KazuCocoa authored Dec 17, 2016
1 parent da4ed34 commit e4b4426
Show file tree
Hide file tree
Showing 30 changed files with 218 additions and 232 deletions.
21 changes: 21 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Metrics/LineLength:
Max: 125
Metrics/MethodLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/CyclomaticComplexity:
Expand All @@ -11,6 +13,8 @@ Metrics/PerceivedComplexity:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/Documentation:
Enabled: false
Style/RegexpLiteral:
Expand All @@ -26,3 +30,20 @@ Style/DoubleNegation:
Enabled: false
Style/EachWithObject:
Enabled: false
Style/SpaceAroundOperators:
Enabled: false
Style/ExtraSpacing:
Enabled: false
Style/IndentHash:
Enabled: false
Style/VariableNumber:
EnforcedStyle: 'snake_case'
# The followings should checked again
Style/IdenticalConditionalBranches:
Enabled: false
Lint/NestedMethodDefinition:
Enabled: false
Lint/UnifiedInteger:
Enabled: false
Performance/RedundantBlockCall:
Enabled: false
8 changes: 3 additions & 5 deletions android_tests/lib/android/specs/android/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,16 @@ def id_value
# api 19
['mFocusedApp=AppWindowToken{b40af858 token=Token{b3e2ce38 ActivityRecord{b3eb47d8 u0 io.appium.android.apis/.ApiDemos t6}}}',
'io.appium.android.apis',
'.ApiDemos'
],
'.ApiDemos'],
# api 16 selendroid
['mFocusedApp=AppWindowToken{4157a2c8 token=Token{41582628 ActivityRecord{415821f0 com.android.launcher/com.android.launcher2.Launcher}}}',
'com.android.launcher',
'com.android.launcher2.Launcher'
]
'com.android.launcher2.Launcher']
]

expected.each do |line, package, activity|
parsed = _parse_current_app_line(line)
fail "failed to parse #{line}" if parsed.nil?
raise "failed to parse #{line}" if parsed.nil?
parsed.package.must_equal package
parsed.activity.must_equal activity
parsed.am_start.must_equal package + '/' + activity
Expand Down
16 changes: 8 additions & 8 deletions android_tests/lib/android/specs/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
wait(wait_opts) { nil }

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

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

# invalid keys are rejected
proc { wait(invalidkey: 2) { true } }.must_raise RuntimeError
Expand All @@ -31,8 +31,8 @@
ignore { true }
ignore { false }
ignore { nil }
ignore { fail }
ignore { fail NoMemoryError }
ignore { raise }
ignore { raise NoMemoryError }
end

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

# raise should error
proc { wait_true(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError
proc { wait_true(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError

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

# invalid keys are rejected
Expand Down
2 changes: 1 addition & 1 deletion android_tests/lib/android/specs/common/web_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def undo_setcontext_nav

if webview_context.nil?
undo_setcontext_nav
fail "No webview context found. contexts are: #{contexts}"
raise "No webview context found. contexts are: #{contexts}"
end

wait { set_context webview_context }
Expand Down
6 changes: 3 additions & 3 deletions android_tests/lib/android/specs/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def sauce?
# change :ios in expected to match 'ios' in actual
# [["~", "caps.platformName", :ios, "ios"]]
message = "\n\nactual:\n\n: #{actual.ai}expected:\n\n#{expected.ai}\n\n#{diff}"
fail message
raise message
end

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

# any elements
Expand All @@ -189,7 +189,7 @@ def validate_path(path)
begin
set_location latitude: 55, longitude: -72, altitude: 33
rescue Selenium::WebDriver::Error::UnknownError => e
# on android this method is expected to fail with this message when running
# on android this method is expected to raise with this message when running
# on a regular device, or on genymotion.
# error could be many messages, including:
# ERROR running Appium command: port should be a number or string
Expand Down
6 changes: 3 additions & 3 deletions android_tests/lib/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

indent = 6
puts ' ' * indent + "when '" + tag + "'"
line2 = ' ' * (indent + 2) + "prefix '" + klass + "'"
line_2 = ' ' * (indent + 2) + "prefix '" + klass + "'"
# button must translate to both button and image button
# for ruby_lib to find all buttons
line2 += ", 'ImageButton'" if klass == 'Button'
puts line2
line_2 += ", 'ImageButton'" if klass == 'Button'
puts line_2
end

# for Pry
Expand Down
12 changes: 7 additions & 5 deletions android_tests/lib/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def start_driver(caps)

# Sanity check
a = OpenStruct.new x: 'ok'
fail 'x issue' unless a.x == 'ok'
raise 'x issue' unless a.x == 'ok'

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

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

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

# require support (common.rb)
Dir.glob(File.join dir, test_dir + '/*.rb') do |test|
file_name = File.join dir, test_dir + '/*.rb'
Dir.glob(file_name) do |test|
require test
trace_files << test
end
Expand All @@ -59,7 +60,8 @@ def start_driver(caps)
trace_files << one_test
else
# require all
Dir.glob(File.join dir, test_dir + '**/*.rb') do |test|
file_names = File.join(dir, test_dir + '**/*.rb')
Dir.glob(file_names) do |test|
# load all tests
trace_files << test
puts " #{File.basename(test, '.*')}"
Expand Down
4 changes: 2 additions & 2 deletions appium_lib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Gem::Specification.new do |s|
s.add_development_dependency 'spec', '~> 5.3', '>= 5.3.4'
s.add_development_dependency 'fakefs', '~> 0.6.7'

s.add_development_dependency 'rake', '~> 10.4'
s.add_development_dependency 'rake', '~> 12.0'
s.add_development_dependency 'yard', '~> 0.8'

s.add_development_dependency 'rubocop', '~> 0.30.1'
s.add_development_dependency 'rubocop', '~> 0.46.0'

s.files = `git ls-files`.split "\n"
end
7 changes: 7 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ Android tests require running on physical hardware with Android 5.0 (API 21). Th
2. Generate release note and create a branch with `rake release`
- Push and merge the branch to the master
3. Build and publish gem with `rake publish`
4. Add release information on GitHub: https://github.com/appium/ruby_lib/releases
- Template
```
1. Enhancements
2. Bug fixes
3. Deprecations
```
66 changes: 11 additions & 55 deletions ios_tests/lib/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,91 +38,47 @@ def self.xcuitest?
end

def self.navbar
if xcuitest?
'XCUIElementTypeNavigationBar'
else
'UIANavigationBar'
end
xcuitest? ? 'XCUIElementTypeNavigationBar' : 'UIANavigationBar'
end

def self.button
if xcuitest?
'XCUIElementTypeButton'
else
'UIAButton'
end
xcuitest? ? 'XCUIElementTypeButton' : 'UIAButton'
end

def self.static_text
if xcuitest?
'XCUIElementTypeStaticText'
else
'UIAStaticText'
end
xcuitest? ? 'XCUIElementTypeStaticText' : 'UIAStaticText'
end

def self.text_field
if xcuitest?
'XCUIElementTypeTextField'
else
'UIATextField'
end
xcuitest? ? 'XCUIElementTypeTextField' : 'UIATextField'
end

def self.secure_text_field
if xcuitest?
'XCUIElementTypeSecureTextField'
else
'UIASecureTextField'
end
xcuitest? ? 'XCUIElementTypeSecureTextField' : 'UIASecureTextField'
end

def self.picker
if xcuitest?
'XCUIElementTypePicker'
else
'UIAPicker'
end
xcuitest? ? 'XCUIElementTypePicker' : 'UIAPicker'
end

def self.action_sheet
if xcuitest?
'XCUIElementTypeActionSheet'
else
'UIActionSheet'
end
xcuitest? ? 'XCUIElementTypeActionSheet' : 'UIActionSheet'
end

def self.table
if xcuitest?
'XCUIElementTypeTable'
else
'UIATable'
end
xcuitest? ? 'XCUIElementTypeTable' : 'UIATable'
end

def self.table_cell
if xcuitest?
'XCUIElementTypeCell'
else
'UIATableCell'
end
xcuitest? ? 'XCUIElementTypeCell' : 'UIATableCell'
end

def self.other
if xcuitest?
'XCUIElementTypeOther'
else
fail 'unknown UIA element: other'
end
xcuitest? ? 'XCUIElementTypeOther' : raise('unknown UIA element: other')
end

def self.status_bar
if xcuitest?
'XCUIElementTypeStatusBar'
else
'UIAStatusBar'
end
xcuitest? ? 'XCUIElementTypeStatusBar' : 'UIAStatusBar'
end
end
end
16 changes: 8 additions & 8 deletions ios_tests/lib/ios/specs/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def before_first
wait(wait_opts) { nil }

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

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

# invalid keys are rejected
proc { wait(invalidkey: 2) { true } }.must_raise RuntimeError
Expand All @@ -40,8 +40,8 @@ def before_first
ignore { true }
ignore { false }
ignore { nil }
ignore { fail }
ignore { fail NoMemoryError }
ignore { raise }
ignore { raise NoMemoryError }
end

# wait_true is a success unless the value is not true
Expand All @@ -54,12 +54,12 @@ def before_first
proc { wait_true(wait_opts) { nil } }.must_raise Selenium::WebDriver::Error::TimeOutError

# raise should error
proc { wait_true(wait_opts) { fail } }.must_raise Selenium::WebDriver::Error::TimeOutError
proc { wait_true(wait_opts) { raise } }.must_raise Selenium::WebDriver::Error::TimeOutError

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

# invalid keys are rejected
Expand Down
Loading

0 comments on commit e4b4426

Please sign in to comment.