Skip to content

Fix remaining rubocop issues #329

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 1 commit into from
Apr 29, 2015
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
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Style/AccessorMethodName:
Enabled: false
Style/DoubleNegation:
Enabled: false
Style/EachWithObject:
Enabled: false
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@ desc 'Execute RuboCop static code analysis'
RuboCop::RakeTask.new(:rubocop) do |t|
t.patterns = %w(lib ios_tests android_tests)
t.options = %w(-D)
t.fail_on_error = false
t.fail_on_error = true
end
5 changes: 0 additions & 5 deletions android_tests/lib/android/specs/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def sauce?
end

describe 'Appium::Driver' do
t '@@loaded' do
loaded = $driver.class.class_variable_get :@@loaded
loaded.must_equal true
end

t '$driver.class' do
$driver.class.must_equal Appium::Driver
end
Expand Down
6 changes: 5 additions & 1 deletion android_tests/lib/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
end

fail "\nTest #{one_test} does not exist.\n" unless File.exist?(one_test)
Appium::Driver.new(caps).start_driver
driver = Appium::Driver.new(caps)
# Tests expect methods defined on the minispec object
Appium.promote_appium_methods ::Minitest::Spec
driver.start_driver

# require support (common.rb)
Dir.glob(File.join dir, test_dir + '/*.rb') do |test|
require test
Expand Down
2 changes: 1 addition & 1 deletion docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Breaking Changes in 7.0

Requires appium 1.4.0-beta or newer for iOS helper methods.
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`

Old | New
:--|:--
Expand Down
5 changes: 0 additions & 5 deletions ios_tests/lib/ios/specs/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ def sauce?
end

describe 'Appium::Driver' do
t '@@loaded' do
loaded = $driver.class.class_variable_get :@@loaded
loaded.must_equal true
end

t '$driver.class' do
$driver.class.must_equal Appium::Driver
end
Expand Down
6 changes: 2 additions & 4 deletions lib/appium_lib/common/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ module Common

# Return block.call and ignore any exceptions.
def ignore(&block)
begin
block.call
rescue Exception
end
block.call
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
end

# Navigate back.
Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib/common/wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _generic_wait(opts = {}, &block)
end
rescue ::Errno::ECONNREFUSED => e
raise e
rescue *ignored => last_error
rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions
# swallowed
end

Expand Down
6 changes: 3 additions & 3 deletions lib/appium_lib/device/touch_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def release(opts = nil)
# @option opts [integer] :y y co-ordinate to tap
# @option opts [integer] :fingers how many fingers to tap with (Default 1)
def tap(opts)
opts[:count] = opts.delete(:fingers) if opts[:fingers]
opts[:count] ||= 1
args = args_with_ele_ref opts
opts[:count] = opts.delete(:fingers) if opts[:fingers]
opts[:count] ||= 1
args = args_with_ele_ref opts
chain_method(:tap, args)
end

Expand Down
34 changes: 10 additions & 24 deletions lib/appium_lib/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def self.symbolize_keys(hash)
fail 'symbolize_keys requires a hash' unless hash.is_a? Hash
result = {}
hash.each do |key, value|
key = key.to_sym rescue key
key = key.to_sym rescue key # rubocop:disable Style/RescueModifier
result[key] = value.is_a?(Hash) ? symbolize_keys(value) : value
end
result
Expand Down Expand Up @@ -216,8 +216,6 @@ def self.promote_appium_methods(class_array)
end

class Driver
@@loaded = false

# attr readers are promoted to global scope. To avoid clobbering, they're
# made available via the driver_attributes method
#
Expand All @@ -232,6 +230,9 @@ class Driver
# Export session id to textfile in /tmp for 3rd party tools
attr_accessor :export_session
# Default wait time for elements to appear
# Returns the default client side wait.
# This value is independent of what the server is using
# @return [Integer]
attr_accessor :default_wait
# Array of previous wait time values
attr_accessor :last_waits
Expand All @@ -246,6 +247,10 @@ class Driver
# Boolean debug mode for the Appium Ruby bindings
attr_accessor :appium_debug

# Returns the driver
# @return [Driver] the driver
attr_reader :driver

# Creates a new driver
#
# ```ruby
Expand Down Expand Up @@ -327,14 +332,6 @@ def initialize(opts = {})
# Save global reference to last created Appium driver for top level methods.
$driver = self

# Promote exactly once the first time the driver is created.
# Subsequent drivers do not trigger promotion.
unless @@loaded
@@loaded = true
# Promote only on Minitest::Spec (minitest 5) by default
Appium.promote_appium_methods ::Minitest::Spec
end

self # return newly created driver
end

Expand Down Expand Up @@ -436,12 +433,6 @@ def restart
start_driver
end

# Returns the driver
# @return [Driver] the driver
def driver
@driver
end

# Takes a png screenshot and saves to the target path.
#
# Example: screenshot '/tmp/hi.png'
Expand All @@ -457,6 +448,7 @@ def screenshot(png_save_path)
# @return [void]
def driver_quit
# rescue NoSuchDriverError or nil driver
# rubocop:disable Style/RescueModifier
@driver.quit rescue nil
end

Expand All @@ -475,6 +467,7 @@ def start_driver

# export session
if @export_session
# rubocop:disable Style/RescueModifier
File.open('/tmp/appium_lib_session', 'w') do |f|
f.puts @driver.session_id
end rescue nil
Expand Down Expand Up @@ -523,13 +516,6 @@ def set_wait(timeout = nil)
@driver.manage.timeouts.implicit_wait = timeout
end

# Returns the default client side wait.
# This value is independent of what the server is using
# @return [Integer]
def default_wait
@default_wait
end

# Returns existence of element.
#
# Example:
Expand Down