<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Class: Caricature::Isolator</title> <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" /> <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script> <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script> <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script> <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script> </head> <body class="class"> <div id="metadata"> <div id="file-metadata"> <div id="file-list-section" class="section"> <h3 class="section-header">In Files</h3> <div class="section-body"> <ul> <li><a href="../lib/caricature/isolator_rb.html?TB_iframe=true&height=550&width=785" class="thickbox" title="lib/caricature/isolator.rb">lib/caricature/isolator.rb</a></li> </ul> </div> </div> </div> <div id="class-metadata"> <!-- Parent Class --> <div id="parent-class-section" class="section"> <h3 class="section-header">Parent</h3> <p class="link"><a href="../Object.html">Object</a></p> </div> <!-- Namespace Contents --> <!-- Method Quickref --> <div id="method-list-section" class="section"> <h3 class="section-header">Methods</h3> <ul class="link-list"> <li><a href="#M000080">::for</a></li> <li><a href="#M000070">::new</a></li> <li><a href="#M000071">#build_isolation</a></li> <li><a href="#M000076">#class_name</a></li> <li><a href="#M000078">#initialize_isolation</a></li> <li><a href="#M000074">#initialize_messenger</a></li> </ul> </div> <!-- Included Modules --> </div> <div id="project-metadata"> <div id="fileindex-section" class="section project-section"> <h3 class="section-header">Files</h3> <ul> <li class="file"><a href="../README_markdown.html">README.markdown</a></li> </ul> </div> <div id="classindex-section" class="section project-section"> <h3 class="section-header">Class Index <span class="search-toggle"><img src="../images/find.png" height="16" width="16" alt="[+]" title="show/hide quicksearch" /></span></h3> <form action="#" method="get" accept-charset="utf-8" class="initially-hidden"> <fieldset> <legend>Quicksearch</legend> <input type="text" name="quicksearch" value="" class="quicksearch-field" /> </fieldset> </form> <ul class="link-list"> <li><a href="../Caricature.html">Caricature</a></li> <li><a href="../Caricature/ArgumentRecording.html">Caricature::ArgumentRecording</a></li> <li><a href="../Caricature/ClrClassDescriptor.html">Caricature::ClrClassDescriptor</a></li> <li><a href="../Caricature/ClrClassMessenger.html">Caricature::ClrClassMessenger</a></li> <li><a href="../Caricature/ClrInterfaceDescriptor.html">Caricature::ClrInterfaceDescriptor</a></li> <li><a href="../Caricature/ClrInterfaceIsolator.html">Caricature::ClrInterfaceIsolator</a></li> <li><a href="../Caricature/ClrInterfaceMessenger.html">Caricature::ClrInterfaceMessenger</a></li> <li><a href="../Caricature/ClrIsolator.html">Caricature::ClrIsolator</a></li> <li><a href="../Caricature/Expectation.html">Caricature::Expectation</a></li> <li><a href="../Caricature/ExpectationBuilder.html">Caricature::ExpectationBuilder</a></li> <li><a href="../Caricature/ExpectationSyntax.html">Caricature::ExpectationSyntax</a></li> <li><a href="../Caricature/Expectations.html">Caricature::Expectations</a></li> <li><a href="../Caricature/Interception.html">Caricature::Interception</a></li> <li><a href="../Caricature/Interception/ClassMethods.html">Caricature::Interception::ClassMethods</a></li> <li><a href="../Caricature/Isolation.html">Caricature::Isolation</a></li> <li><a href="../Caricature/Isolator.html">Caricature::Isolator</a></li> <li><a href="../Caricature/MemberDescriptor.html">Caricature::MemberDescriptor</a></li> <li><a href="../Caricature/Messenger.html">Caricature::Messenger</a></li> <li><a href="../Caricature/MethodCallRecorder.html">Caricature::MethodCallRecorder</a></li> <li><a href="../Caricature/MethodCallRecording.html">Caricature::MethodCallRecording</a></li> <li><a href="../Caricature/RubyIsolator.html">Caricature::RubyIsolator</a></li> <li><a href="../Caricature/RubyMessenger.html">Caricature::RubyMessenger</a></li> <li><a href="../Caricature/RubyObjectDescriptor.html">Caricature::RubyObjectDescriptor</a></li> <li><a href="../Caricature/TypeDescriptor.html">Caricature::TypeDescriptor</a></li> <li><a href="../Caricature/Verification.html">Caricature::Verification</a></li> <li><a href="../System.html">System</a></li> <li><a href="../System/String.html">System::String</a></li> <li><a href="../System/Type.html">System::Type</a></li> <li><a href="../Array.html">Array</a></li> <li><a href="../Class.html">Class</a></li> <li><a href="../Hash.html">Hash</a></li> <li><a href="../Module.html">Module</a></li> <li><a href="../Object.html">Object</a></li> <li><a href="../String.html">String</a></li> </ul> <div id="no-class-search-results" style="display: none;">No matching classes.</div> </div> </div> </div> <div id="documentation"> <h1 class="class">Caricature::Isolator</h1> <div id="description"> <p> A base class for <tt>Isolator</tt> objects to stick with the <tt>Isolation</tt> 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. </p> </div> <!-- Constants --> <!-- Attributes --> <div id="attribute-method-details" class="method-section section"> <h3 class="section-header">Attributes</h3> <div id="isolation-attribute-method" class="method-detail"> <a name="isolation"></a> <div class="method-heading attribute-method-heading"> <span class="method-name">isolation</span><span class="attribute-access-type">[R]</span> </div> <div class="method-description"> <p> holds the isolation created by this isolator </p> </div> </div> <div id="subject-attribute-method" class="method-detail"> <a name="subject"></a> <div class="method-heading attribute-method-heading"> <span class="method-name">subject</span><span class="attribute-access-type">[R]</span> </div> <div class="method-description"> <p> holds the subject of this isolator </p> </div> </div> <div id="descriptor-attribute-method" class="method-detail"> <a name="descriptor"></a> <div class="method-heading attribute-method-heading"> <span class="method-name">descriptor</span><span class="attribute-access-type">[R]</span> </div> <div class="method-description"> <p> holds the descriptor for this type of object </p> </div> </div> </div> <!-- Methods --> <div id="public-class-method-details" class="method-section section"> <h3 class="section-header">Public Class Methods</h3> <div id="for-method" class="method-detail "> <a name="M000080"></a> <div class="method-heading"> <span class="method-name">for</span><span class="method-args">(context)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> Creates the actual proxy object for the <tt>subject</tt> and initializes it with a <tt>recorder</tt> and <tt>expectations</tt> This is the actual isolation that will be used to in your tests. It implements all the methods of the <tt>subject</tt> 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. </p> <div class="method-source-code" id="for-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 219</span> <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">for</span>(<span class="ruby-identifier">context</span>) <span class="ruby-identifier">context</span>.<span class="ruby-identifier">recorder</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">MethodCallRecorder</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">context</span>.<span class="ruby-identifier">expectations</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Expectations</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">new</span>(<span class="ruby-identifier">context</span>) <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div id="new-method" class="method-detail "> <a name="M000070"></a> <div class="method-heading"> <span class="method-name">new</span><span class="method-args">(context)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> creates a new instance of an isolator </p> <div class="method-source-code" id="new-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 177</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">context</span>) <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">context</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> </div> <div id="public-instance-method-details" class="method-section section"> <h3 class="section-header">Public Instance Methods</h3> <div id="build-isolation-method" class="method-detail "> <a name="M000071"></a> <div class="method-heading"> <span class="method-name">build_isolation</span><span class="method-args">(klass, inst=nil)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> builds up the isolation class instance </p> <div class="method-source-code" id="build-isolation-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 182</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_isolation</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">inst</span>=<span class="ruby-keyword kw">nil</span>) <span class="ruby-identifier">pxy</span> = <span class="ruby-identifier">create_isolation_for</span> <span class="ruby-identifier">klass</span> <span class="ruby-ivar">@isolation</span> = <span class="ruby-identifier">pxy</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@subject</span> = <span class="ruby-identifier">inst</span> <span class="ruby-identifier">initialize_messenger</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div id="class-name-method" class="method-detail "> <a name="M000076"></a> <div class="method-heading"> <span class="method-name">class_name</span><span class="method-args">(subj)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> Creates the new class name for the isolation </p> <div class="method-source-code" id="class-name-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 195</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_name</span>(<span class="ruby-identifier">subj</span>) <span class="ruby-identifier">nm</span> = <span class="ruby-identifier">subj</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:class_eval</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">subj</span>.<span class="ruby-identifier">demodulize</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">subj</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">demodulize</span> <span class="ruby-ivar">@class_name</span> = <span class="ruby-node">"#{nm}#{System::Guid.new_guid.to_string('n')}"</span> <span class="ruby-ivar">@class_name</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div id="initialize-isolation-method" class="method-detail "> <a name="M000078"></a> <div class="method-heading"> <span class="method-name">initialize_isolation</span><span class="method-args">(klass, context)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> Sets up the necessary instance variables for the isolation </p> <div class="method-source-code" id="initialize-isolation-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 202</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize_isolation</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">context</span>) <span class="ruby-identifier">pxy</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">pxy</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">"@___context___"</span>, <span class="ruby-identifier">context</span>) <span class="ruby-identifier">pxy</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div id="initialize-messenger-method" class="method-detail "> <a name="M000074"></a> <div class="method-heading"> <span class="method-name">initialize_messenger</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p> initializes the messaging strategy for the isolator </p> <div class="method-source-code" id="initialize-messenger-source"> <pre> <span class="ruby-comment cmt"># File lib/caricature/isolator.rb, line 190</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize_messenger</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> </div> </div> <div id="rdoc-debugging-section-dump" class="debugging-section"> <p>Disabled; run with --debug to generate this.</p> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 1.1.6</small>.</p> </div> </body> </html>