Instead of using confusing terms like Mocking and Stubbing which is basically the same. Caricature tries to unify those concepts by using a term of Isolation. When you’re testing you typically want to be in control of what you’re testing. To do that you isolate dependencies and possibly define return values for methods on them. At a later stage you might be interested in which method was called, maybe even with which parameters or you might be interested in the amount of times it has been called.
Creates an isolation object complete with proxy and method call recorder It works out which isolation it needs to create and provide and initializes the method call recorder
# File lib/caricature/clr/isolation.rb, line 10 def for(subject, recorder = MethodCallRecorder.new, expectations = Expectations.new) context = IsolatorContext.new subject, recorder, expectations isolation_strategy = subject.is_clr_type? ? get_clr_isolation_strategy(subject) : RubyIsolator isolator = isolation_strategy.for context isolation = new(isolator, context) isolator.isolation end
Creates an isolation object complete with proxy and method call recorder It works out which isolation it needs to create and provide and initializes the method call recorder
# File lib/caricature/isolation.rb, line 113 def for(subject, recorder = MethodCallRecorder.new, expectations = Expectations.new) context = IsolatorContext.new subject, recorder, expectations isolator = RubyIsolator.for context isolation = new(isolator, context) isolator.isolation end
Initializes a new instance of this isolation.
# File lib/caricature/isolation.rb, line 65 def initialize(isolator, context) @instance = isolator.subject @recorder = context.recorder @messenger = context.messenger @expectations = context.expectations isolator.isolation.class.instance_variable_set("@___context___", self) end
decides which startegy to use for mocking a CLR object. When the provided subject is an interface it will return a ClrInterfaceIsolator otherwise it will return a ClrIsolator
# File lib/caricature/clr/isolation.rb, line 24 def get_clr_isolation_strategy(subject) return ClrInterfaceIsolator if subject.respond_to? :class_eval and !subject.respond_to? :new ClrIsolator end
asserts whether the method has been called for the specified configuration
# File lib/caricature/isolation.rb, line 104 def class_verify(method_name, &block) internal_verify method_name, :class, &block end
builds up an expectation for a class method, allows for overriding the result returned by the class method
# File lib/caricature/isolation.rb, line 93 def create_class_override(method_name, &block) puts "creating override" internal_create_override method_name, :class, &block end
builds up an expectation for an instance method, allows for overriding the result returned by the method
# File lib/caricature/isolation.rb, line 88 def create_override(method_name, &block) internal_create_override method_name, :instance, &block end
record and send the message to the isolation. takes care of following expectations rules when sending messages.
# File lib/caricature/isolation.rb, line 82 def send_class_message(method_name, return_type, *args, &b) recorder.record_call method_name, :class, *args, &b @messenger.deliver_to_class(method_name, return_type, *args, &b) end
record and send the message to the isolation. takes care of following expectations rules when sending messages.
# File lib/caricature/isolation.rb, line 75 def send_message(method_name, return_type, *args, &b) recorder.record_call method_name, :instance, *args, &b @messenger.deliver(method_name, return_type, *args, &b) end
(Not documented)
# File lib/caricature/isolation.rb, line 125 def internal_create_override(method_name, mode=:instance, &block) builder = ExpectationBuilder.new method_name block.call builder unless block.nil? exp = builder.build expectations.add_expectation exp, mode exp end
(Not documented)
# File lib/caricature/isolation.rb, line 133 def internal_verify(method_name, mode=:instance, &block) verification = Verification.new(method_name, recorder, mode) block.call verification unless block.nil? verification end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.