lib/caricature/messenger.rb in caricature-0.7.0 vs lib/caricature/messenger.rb in caricature-0.7.1
- old
+ new
@@ -1,10 +1,13 @@
module Caricature
# A base class to encapsulate method invocation
class Messenger
+ # contains the recorder for recording method calls
+ attr_accessor :recorder
+
# the real instance of the isolated subject
# used to forward calls in partial mocks
attr_reader :instance
# the expecations that have been set for the isolation
@@ -30,10 +33,15 @@
# template method for looking up the expectation and/or returning a value
def internal_deliver(mode, method_name, return_type, *args, &b)
raise NotImplementedError.new("Override in an implementing class")
end
+
+ private
+ def record_call(method_name, mode, expectation, *args, &b)
+ recorder.record_call method_name, mode, expectation, *args, &b if recorder
+ end
end
# Encapsulates sending messages to Ruby isolations
class RubyMessenger < Messenger
@@ -41,13 +49,15 @@
protected
# implementation of the template method for looking up the expectation and/or returning a value
def internal_deliver(mode, method_name, return_type, *args, &b)
exp = expectations.find(method_name, mode, *args)
- if exp
- res = instance.__send__(method_name, *args, &b) if exp.super_before?
- res = exp.execute *args
- res = instance.__send__(method_name, *args, &b) if !exp.super_before? and exp.call_super?
+ bl = record_call(method_name, mode, exp, *args, &b)
+ if exp
+ block = exp.block || b
+ res = instance.__send__(method_name, *args, &block) if exp.super_before?
+ res = exp.execute *args, &bl
+ res = instance.__send__(method_name, *args, &block) if !exp.super_before? and exp.call_super?
res
else
nil
end
end
\ No newline at end of file