Skip to content

Commit e9d1986

Browse files
Fix remaining rubocop issues
1 parent 7feace9 commit e9d1986

File tree

10 files changed

+25
-45
lines changed

10 files changed

+25
-45
lines changed

.rubocop.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ Style/AccessorMethodName:
2626
Enabled: false
2727
Style/DoubleNegation:
2828
Enabled: false
29+
Style/EachWithObject:
30+
Enabled: false

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,5 @@ desc 'Execute RuboCop static code analysis'
233233
RuboCop::RakeTask.new(:rubocop) do |t|
234234
t.patterns = %w(lib ios_tests android_tests)
235235
t.options = %w(-D)
236-
t.fail_on_error = false
236+
t.fail_on_error = true
237237
end

android_tests/lib/android/specs/driver.rb

-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ def sauce?
6161
end
6262

6363
describe 'Appium::Driver' do
64-
t '@@loaded' do
65-
loaded = $driver.class.class_variable_get :@@loaded
66-
loaded.must_equal true
67-
end
68-
6964
t '$driver.class' do
7065
$driver.class.must_equal Appium::Driver
7166
end

android_tests/lib/run.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
end
4141

4242
fail "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)
43-
Appium::Driver.new(caps).start_driver
43+
driver = Appium::Driver.new(caps)
44+
# Tests expect methods defined on the minispec object
45+
Appium.promote_appium_methods ::Minitest::Spec
46+
driver.start_driver
47+
4448
# require support (common.rb)
4549
Dir.glob(File.join dir, test_dir + '/*.rb') do |test|
4650
require test

docs/migration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Breaking Changes in 7.0
22

3-
Requires appium 1.4.0-beta or newer for iOS helper methods.
3+
Requires appium 1.4.0-beta or newer for iOS helper methods. appium_lib no longer automatically promotes methods on minispec. To restore the old behavior use: `Appium.promote_appium_methods ::Minitest::Spec`
44

55
Old | New
66
:--|:--

ios_tests/lib/ios/specs/driver.rb

-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ def sauce?
119119
end
120120

121121
describe 'Appium::Driver' do
122-
t '@@loaded' do
123-
loaded = $driver.class.class_variable_get :@@loaded
124-
loaded.must_equal true
125-
end
126-
127122
t '$driver.class' do
128123
$driver.class.must_equal Appium::Driver
129124
end

lib/appium_lib/common/helper.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ module Common
2222

2323
# Return block.call and ignore any exceptions.
2424
def ignore(&block)
25-
begin
26-
block.call
27-
rescue Exception
28-
end
25+
block.call
26+
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
2927
end
3028

3129
# Navigate back.

lib/appium_lib/common/wait.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _generic_wait(opts = {}, &block)
3232
end
3333
rescue ::Errno::ECONNREFUSED => e
3434
raise e
35-
rescue *ignored => last_error
35+
rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions
3636
# swallowed
3737
end
3838

lib/appium_lib/device/touch_actions.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def release(opts = nil)
7878
# @option opts [integer] :y y co-ordinate to tap
7979
# @option opts [integer] :fingers how many fingers to tap with (Default 1)
8080
def tap(opts)
81-
opts[:count] = opts.delete(:fingers) if opts[:fingers]
82-
opts[:count] ||= 1
83-
args = args_with_ele_ref opts
81+
opts[:count] = opts.delete(:fingers) if opts[:fingers]
82+
opts[:count] ||= 1
83+
args = args_with_ele_ref opts
8484
chain_method(:tap, args)
8585
end
8686

lib/appium_lib/driver.rb

+10-24
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def self.symbolize_keys(hash)
140140
fail 'symbolize_keys requires a hash' unless hash.is_a? Hash
141141
result = {}
142142
hash.each do |key, value|
143-
key = key.to_sym rescue key
143+
key = key.to_sym rescue key # rubocop:disable Style/RescueModifier
144144
result[key] = value.is_a?(Hash) ? symbolize_keys(value) : value
145145
end
146146
result
@@ -216,8 +216,6 @@ def self.promote_appium_methods(class_array)
216216
end
217217

218218
class Driver
219-
@@loaded = false
220-
221219
# attr readers are promoted to global scope. To avoid clobbering, they're
222220
# made available via the driver_attributes method
223221
#
@@ -232,6 +230,9 @@ class Driver
232230
# Export session id to textfile in /tmp for 3rd party tools
233231
attr_accessor :export_session
234232
# Default wait time for elements to appear
233+
# Returns the default client side wait.
234+
# This value is independent of what the server is using
235+
# @return [Integer]
235236
attr_accessor :default_wait
236237
# Array of previous wait time values
237238
attr_accessor :last_waits
@@ -246,6 +247,10 @@ class Driver
246247
# Boolean debug mode for the Appium Ruby bindings
247248
attr_accessor :appium_debug
248249

250+
# Returns the driver
251+
# @return [Driver] the driver
252+
attr_reader :driver
253+
249254
# Creates a new driver
250255
#
251256
# ```ruby
@@ -327,14 +332,6 @@ def initialize(opts = {})
327332
# Save global reference to last created Appium driver for top level methods.
328333
$driver = self
329334

330-
# Promote exactly once the first time the driver is created.
331-
# Subsequent drivers do not trigger promotion.
332-
unless @@loaded
333-
@@loaded = true
334-
# Promote only on Minitest::Spec (minitest 5) by default
335-
Appium.promote_appium_methods ::Minitest::Spec
336-
end
337-
338335
self # return newly created driver
339336
end
340337

@@ -436,12 +433,6 @@ def restart
436433
start_driver
437434
end
438435

439-
# Returns the driver
440-
# @return [Driver] the driver
441-
def driver
442-
@driver
443-
end
444-
445436
# Takes a png screenshot and saves to the target path.
446437
#
447438
# Example: screenshot '/tmp/hi.png'
@@ -457,6 +448,7 @@ def screenshot(png_save_path)
457448
# @return [void]
458449
def driver_quit
459450
# rescue NoSuchDriverError or nil driver
451+
# rubocop:disable Style/RescueModifier
460452
@driver.quit rescue nil
461453
end
462454

@@ -475,6 +467,7 @@ def start_driver
475467

476468
# export session
477469
if @export_session
470+
# rubocop:disable Style/RescueModifier
478471
File.open('/tmp/appium_lib_session', 'w') do |f|
479472
f.puts @driver.session_id
480473
end rescue nil
@@ -523,13 +516,6 @@ def set_wait(timeout = nil)
523516
@driver.manage.timeouts.implicit_wait = timeout
524517
end
525518

526-
# Returns the default client side wait.
527-
# This value is independent of what the server is using
528-
# @return [Integer]
529-
def default_wait
530-
@default_wait
531-
end
532-
533519
# Returns existence of element.
534520
#
535521
# Example:

0 commit comments

Comments
 (0)