lib/rspec/mocks/verifying_proxy.rb in rspec-mocks-3.3.0 vs lib/rspec/mocks/verifying_proxy.rb in rspec-mocks-3.3.1
- old
+ new
@@ -2,10 +2,25 @@
RSpec::Support.require_rspec_mocks 'method_reference'
module RSpec
module Mocks
# @private
+ class CallbackInvocationStrategy
+ def call(doubled_module)
+ RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
+ block.call doubled_module
+ end
+ end
+ end
+
+ # @private
+ class NoCallbackInvocationStrategy
+ def call(_doubled_module)
+ end
+ end
+
+ # @private
module VerifyingProxyMethods
def add_stub(method_name, opts={}, &implementation)
ensure_implemented(method_name)
super
end
@@ -84,25 +99,26 @@
@method_doubles[method_name].validate_arguments!(args)
end
end
# @private
+ DEFAULT_CALLBACK_INVOCATION_STRATEGY = CallbackInvocationStrategy.new
+
+ # @private
class VerifyingPartialDoubleProxy < PartialDoubleProxy
include VerifyingProxyMethods
- def initialize(object, expectation_ordering)
+ def initialize(object, expectation_ordering, optional_callback_invocation_strategy=DEFAULT_CALLBACK_INVOCATION_STRATEGY)
super(object, expectation_ordering)
@doubled_module = DirectObjectReference.new(object)
# A custom method double is required to pass through a way to lookup
# methods to determine their parameters.
@method_doubles = Hash.new do |h, k|
h[k] = VerifyingExistingMethodDouble.for(object, k, self)
end
- RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
- block.call @doubled_module
- end
+ optional_callback_invocation_strategy.call(@doubled_module)
end
def method_reference
@method_doubles
end