lib/caricature/isolation.rb in caricature-0.6.3 vs lib/caricature/isolation.rb in caricature-0.7.0

- old
+ new

@@ -51,11 +51,11 @@ # or you might be interested in the amount of times it has been called. class Isolation # the real instance of the isolated subject # used to forward calls in partial mocks - attr_reader :instance + attr_accessor :instance # the method call recorder attr_reader :recorder # the expecations set for this isolation @@ -64,11 +64,12 @@ # Initializes a new instance of this isolation. def initialize(isolator, context) @instance = isolator.subject @recorder = context.recorder @messenger = context.messenger - @expectations = context.expectations + @expectations = context.expectations + @proxy = isolator.isolation isolator.isolation.class.instance_variable_set("@___context___", self) end # record and send the message to the isolation. # takes care of following expectations rules when sending messages. @@ -122,10 +123,15 @@ protected def internal_create_override(method_name, mode=:instance, &block) builder = ExpectationBuilder.new method_name block.call builder unless block.nil? - exp = builder.build + exp = builder.build + @proxy.class.send((mode == :instance ? :define_method : :define_cmethod), method_name.to_sym, lambda do |*args| + b = nil + b = Proc.new { yield } if block_given? + isolation_context.send_message(method_name, nil, *args, &b) + end) expectations.add_expectation exp, mode exp end def internal_verify(method_name, mode=:instance, &block) \ No newline at end of file