Parent

Files

Caricature::Isolator

A base class for Isolator objects to stick with the Isolation nomenclature the strategies for creating isolations are called isolators. An isolator functions as a barrier between the code in your test and the underlying type/instance. It allows you to take control over the value that is returned from a specific method, if you want to pass the method call along to the underlying instance etc. It also contains the ability to verify if a method was called, with which arguments etc.

Attributes

isolation[R]

holds the isolation created by this isolator

subject[R]

holds the subject of this isolator

descriptor[R]

holds the descriptor for this type of object

Public Class Methods

for(context) click to toggle source

Creates the actual proxy object for the subject and initializes it with a recorder and expectations This is the actual isolation that will be used to in your tests. It implements all the methods of the subject so as long as you’re in Ruby and just need to isolate out some classes defined in a statically compiled language it should get you all the way there for public instance methods at this point. when you’re going to isolation for usage within a statically compiled language type then you’re bound to most of their rules. So you need to either isolate interfaces or mark the methods you want to isolate as virtual in your implementing classes.

     # File lib/caricature/isolator.rb, line 230
230:       def for(context)
231:         context.recorder ||= MethodCallRecorder.new
232:         context.expectations ||= Expectations.new
233:         new(context)
234:       end
new(context) click to toggle source

creates a new instance of an isolator

     # File lib/caricature/isolator.rb, line 187
187:     def initialize(context)
188:       @context = context
189:     end

Public Instance Methods

build_isolation(klass, inst=nil) click to toggle source

builds up the isolation class instance

     # File lib/caricature/isolator.rb, line 192
192:     def build_isolation(klass, inst=nil)
193:       pxy = create_isolation_for klass
194:       @isolation = pxy.new
195:       @subject = inst
196:       initialize_messenger
197:     end
class_name(subj) click to toggle source

Creates the new class name for the isolation

     # File lib/caricature/isolator.rb, line 205
205:     def class_name(subj)
206:       nm = subj.respond_to?(:class_eval) ? subj.demodulize : subj.class.demodulize
207:       @class_name = "#{nm}#{UUIDTools::UUID.random_create.to_s.gsub /-/, ''}"
208:       @class_name
209:     end
initialize_isolation(klass, context) click to toggle source

Sets up the necessary instance variables for the isolation

     # File lib/caricature/isolator.rb, line 212
212:     def initialize_isolation(klass, context)
213:       pxy = klass.new
214:       pxy.instance_variable_set("@___context___", context)
215:       pxy
216:     end
initialize_messenger() click to toggle source

initializes the messaging strategy for the isolator

     # File lib/caricature/isolator.rb, line 200
200:     def initialize_messenger
201:       raise NotImplementedError
202:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.