lib/spy/subroutine.rb in spy-0.4.5 vs lib/spy/subroutine.rb in spy-1.0.0
- old
+ new
@@ -30,10 +30,11 @@
# @param method_name <Symbol>
# @param singleton_method <Boolean> spy on the singleton method or the normal method
def initialize(object, method_name, singleton_method = true)
@base_object, @method_name = object, method_name
@singleton_method = singleton_method
+ @plan = nil
reset!
end
# hooks the method into the object and stashes original method if it exists
# @param [Hash] opts what do do when hooking into a method
@@ -280,19 +281,30 @@
def arity_range
@arity_range ||=
if original_method
min = max = 0
+ key_args = false
+ opt_keys = false
original_method.parameters.each do |type,_|
case type
when :req
min += 1
max += 1
when :opt
max += 1
when :rest
max = Float::INFINITY
+ when :keyreq
+ key_args = true
+ when :keyrest, :key
+ key_args = true
+ opt_keys = true
end
+ end
+ if key_args
+ max += 1
+ min += 1 unless opt_keys
end
(min..max)
end
end