lib/spy/subroutine.rb in spy-0.3.1 vs lib/spy/subroutine.rb in spy-0.4.0
- old
+ new
@@ -191,13 +191,12 @@
# check if the method was called with the exact arguments
# @param args Arguments that should have been sent to the method
# @return [Boolean]
def has_been_called_with?(*args)
raise NeverHookedError unless @was_hooked
- calls.any? do |call_log|
- call_log.args == args
- end
+ match = block_given? ? Proc.new : proc { |call| call.args == args }
+ calls.any?(&match)
end
# invoke that the method has been called. You really shouldn't use this
# method.
def invoke(object, args, block, called_from)
@@ -329,10 +328,12 @@
def get(base_object, method_name, singleton_method = true)
if singleton_method
if base_object.respond_to?(method_name, true)
spied_method = base_object.method(method_name)
end
- elsif (base_object.instance_methods + base_object.private_instance_methods).include?(method_name)
+ elsif (base_object.public_instance_methods +
+ base_object.protected_instance_methods +
+ base_object.private_instance_methods).include?(method_name)
spied_method = base_object.instance_method(method_name)
end
if spied_method
Agency.instance.find(get_spy_id(spied_method))