Skip to content

Commit 2eb4bb0

Browse files
Check method exists before calling
1 parent 8d48ca2 commit 2eb4bb0

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lib/appium_lib.rb

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ def self.method_missing method, *args, &block
88
raise "driver is nil. called #{method}" if $driver == nil
99

1010
if $driver.respond_to?(method)
11-
# puts "[method_missing] Calling driver.send for #{method}"
12-
$driver.send( method, *args, &block )
11+
# puts "[method_missing] Calling driver.send for #{method}"
12+
$driver.send(method, *args, &block)
13+
elsif self.respond_to?(method)
14+
# puts "[method_missing] Calling super for #{method}"
15+
super(*args, &block)
1316
else
14-
# puts "[method_missing] Calling super for #{method}"
15-
super(*args, &block )
16-
end
17+
super
18+
end
1719
end
1820

1921
module Appium
2022
# @private
2123
def self.add_to_path file, path=false
22-
path = path ? "../#{path}/" : '..'
23-
path = File.expand_path path, file
24+
path = path ? "../#{path}/" : '..'
25+
path = File.expand_path path, file
2426

25-
$:.unshift path unless $:.include? path
27+
$:.unshift path unless $:.include? path
2628
end
2729

2830
add_to_path __FILE__

lib/appium_lib/driver.rb

+8-9
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,14 @@ def initialize opts={}
191191
$driver.public_methods(false).each do | m |
192192
Object.class_eval do
193193
define_method m do | *args, &block |
194-
begin
195-
# puts "[Object.class_eval] Calling super for #{m}"
196-
# prefer existing method.
197-
# super will invoke method missing on driver
198-
super(*args, &block)
199-
rescue NoMethodError
200-
# puts '[Object.class_eval] NoMethodError'
201-
$driver.send m, *args, &block
202-
end
194+
if defined?(super) # check if method is defined on super
195+
# puts "[Object.class_eval] Calling super for #{m}"
196+
# prefer existing method.
197+
super(*args, &block)
198+
else
199+
# puts '[Object.class_eval] not on super, calling driver.'
200+
$driver.send m, *args, &block
201+
end
203202
end
204203
end
205204
end

0 commit comments

Comments
 (0)