<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Dfect</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" /> <script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script> <script src="../js/main.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div class="banner"> <h1> <span class="type">Module</span> Dfect </h1> <ul class="files"> <li><a href="../files/lib/dfect_rb.html">lib/dfect.rb</a></li> </ul> </div> <div id="bodyContent"> <div id="content"> <div class="sectiontitle">Methods</div> <dl class="methods"> <dt>#</dt> <dd> <ul> <li><a href="#M000008"><</a>,</li> <li><a href="#M000010"><<</a>,</li> <li><a href="#M000009">></a>,</li> <li><a href="#M000011">>></a></li> </ul> </dd> <dt>C</dt> <dd> <ul> <li><a href="#M000019">C</a>,</li> <li><a href="#M000020">C!</a>,</li> <li><a href="#M000021">C?</a></li> </ul> </dd> <dt>D</dt> <dd> <ul> <li><a href="#M000007">D</a></li> </ul> </dd> <dt>E</dt> <dd> <ul> <li><a href="#M000016">E</a>,</li> <li><a href="#M000017">E!</a>,</li> <li><a href="#M000018">E?</a></li> </ul> </dd> <dt>F</dt> <dd> <ul> <li><a href="#M000015">F?</a></li> </ul> </dd> <dt>S</dt> <dd> <ul> <li><a href="#M000022">S</a></li> </ul> </dd> <dt>T</dt> <dd> <ul> <li><a href="#M000012">T</a>,</li> <li><a href="#M000013">T!</a>,</li> <li><a href="#M000014">T?</a></li> </ul> </dd> <dt>R</dt> <dd> <ul> <li><a href="#M000023">run</a></li> </ul> </dd> <dt>S</dt> <dd> <ul> <li><a href="#M000024">stop</a></li> </ul> </dd> </dl> <div class="sectiontitle">Constants</div> <table border='0' cellpadding='5'> <tr valign='top'> <td class="attr-name">D</td> <td>=</td> <td class="attr-value">self</td> </tr> <tr valign='top'> <td> </td> <td colspan="2" class="attr-desc"><p> Allows before and after hooks to be specified via the D() method syntax when this module is mixed-in: </p> <pre> D .<< { puts "before all nested tests" } D .< { puts "before each nested test" } D .> { puts "after each nested test" } D .>> { puts "after all nested tests" } </pre> </td> </tr> </table> <div class="sectiontitle">Attributes</div> <table border='0' cellpadding='5'> <tr valign='top'> <td class='attr-rw'> [R] </td> <td class='attr-name'>report</td> <td class='attr-desc'><p> Hash of test results, assembled by <a href="Dfect.html#M000023">run</a>. </p> <dl> <dt>:execution</dt><dd>Hierarchical trace of all tests executed, where each test is represented by its description, is mapped to an Array of nested tests, and may contain zero or more assertion failures. <p> Assertion failures are represented as a Hash: </p> <dl> <dt>“fail“</dt><dd>Description of the assertion failure. </dd> <dt>“code“</dt><dd>Source code surrounding the point of failure. </dd> <dt>“vars“</dt><dd>Local variables visible at the point of failure. </dd> <dt>“call“</dt><dd>Stack trace leading to the point of failure. </dd> </dl> </dd> <dt>:statistics</dt><dd>Hash of counts of major events in test execution: <dl> <dt>:passed_assertions</dt><dd>Number of assertions that held true. </dd> <dt>:failed_assertions</dt><dd>Number of assertions that did not hold true. </dd> <dt>:uncaught_exceptions</dt><dd>Number of exceptions that were not rescued. </dd> </dl> </dd> </dl></td> </tr> <tr valign='top'> <td class='attr-rw'> [RW] </td> <td class='attr-name'>options</td> <td class='attr-desc'><p> Hash of choices that affect how <a href="Dfect.html">Dfect</a> operates. </p> <dl> <dt>:debug</dt><dd>Launch an interactive debugger during assertion failures so the user can investigate them. <p> The default value is true. </p> </dd> <dt>:quiet</dt><dd>Do not print the report after executing all tests. <p> The default value is false. </p> </dd> </dl></td> </tr> </table> <div class="sectiontitle">Class Public methods</div> <div class="method"> <div class="title" id="M000008"> <a name="M000008"></a><b> <(&block) </b> </div> <div class="description"> <p> Registers the given block to be executed before each nested test inside this test. </p> <h4>Examples</h4> <pre> D .< { puts "before each nested test" } D .< do puts "before each nested test" end </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L146" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000008_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 146</span> <span class="ruby-keyword kw">def</span> <span class="ruby-operator"><</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span> <span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">before_each</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># the < method is being used as a check for inheritance</span> <span class="ruby-keyword kw">super</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000010"> <a name="M000010"></a><b><<</b>(&block) </div> <div class="description"> <p> Registers the given block to be executed before all nested tests inside this test. </p> <h4>Examples</h4> <pre> D .<< { puts "before all nested tests" } D .<< do puts "before all nested tests" end </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L185" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000010_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 185</span> <span class="ruby-keyword kw">def</span> <span class="ruby-operator"><<</span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span> <span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">before_all</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000009"> <a name="M000009"></a><b>></b>(&block) </div> <div class="description"> <p> Registers the given block to be executed after each nested test inside this test. </p> <h4>Examples</h4> <pre> D .> { puts "after each nested test" } D .> do puts "after each nested test" end </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L168" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000009_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 168</span> <span class="ruby-keyword kw">def</span> <span class="ruby-operator">></span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span> <span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">after_each</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000011"> <a name="M000011"></a><b>>></b>(&block) </div> <div class="description"> <p> Registers the given block to be executed after all nested tests inside this test. </p> <h4>Examples</h4> <pre> D .>> { puts "after all nested tests" } D .>> do puts "after all nested tests" end </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L202" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000011_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 202</span> <span class="ruby-keyword kw">def</span> <span class="ruby-operator">>></span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span> <span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">after_all</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000019"> <a name="M000019"></a><b>C</b>(message = nil, symbol = nil, &block) </div> <div class="description"> <p> Asserts that the given symbol is thrown when the given block is executed. </p> <p> If a value is thrown along with the expected symbol, then that value is returned. </p> <p> Otherwise, nil is returned. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> <dt>symbol</dt><dd>Symbol that must be thrown by the given block. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: C(:foo) { throw :foo, 123 } # passes, => 123 C(:foo) { throw :bar, 456 } # fails, => 456 C(:foo) { } # fails, => nil # message specified: C( ":foo must be thrown", :foo ) { throw :bar, 789 } # fails, => nil </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000019_source')" id="l_M000019_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L464" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000019_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 464</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">C</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">symbol</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_catch</span> <span class="ruby-identifier">:assert</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000020"> <a name="M000020"></a><b>C!</b>(message = nil, symbol = nil, &block) </div> <div class="description"> <p> Asserts that the given symbol is not thrown when the given block is executed. </p> <p> Returns nil, always. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> <dt>symbol</dt><dd>Symbol that must not be thrown by the given block. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: C!(:foo) { throw :foo, 123 } # fails, => nil C!(:foo) { throw :bar, 456 } # passes, => nil C!(:foo) { } # passes, => nil # message specified: C!( ":foo must be thrown", :foo ) { throw :bar, 789 } # passes, => nil </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000020_source')" id="l_M000020_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L495" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000020_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 495</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">C!</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">symbol</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_catch</span> <span class="ruby-identifier">:negate</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000021"> <a name="M000021"></a><b>C?</b>(message = nil, symbol = nil, &block) </div> <div class="description"> <p> Returns true if the given symbol is thrown when the given block is executed. Otherwise, returns false. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>This parameter is optional and completely ignored. </dd> <dt>symbol</dt><dd>Symbol that must be thrown by the given block. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: C?(:foo) { throw :foo, 123 } # => true C?(:foo) { throw :bar, 456 } # => false C?(:foo) { } # => false # message specified: C?( ":foo must be thrown", :foo ) { throw :bar, 789 } # => false </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000021_source')" id="l_M000021_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L523" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000021_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 523</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">C?</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">symbol</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_catch</span> <span class="ruby-identifier">:sample</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">symbol</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000007"> <a name="M000007"></a><b>D</b>(description = caller.first, &block) </div> <div class="description"> <p> Defines a new test, composed of the given description and the given block to execute. </p> <p> A test may contain nested tests. </p> <h4>Parameters</h4> <dl> <dt>description</dt><dd>A short summary of the test being defined. </dd> </dl> <h4>Examples</h4> <pre> D "a new array" do D .< { @array = [] } D "must be empty" do T { @array.empty? } end D "when populated" do D .< { @array.push 55 } D "must not be empty" do F { @array.empty? } end end end </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L127" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000007_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 127</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">D</span> <span class="ruby-identifier">description</span> = <span class="ruby-identifier">caller</span>.<span class="ruby-identifier">first</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span> <span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">tests</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">Suite</span><span class="ruby-operator">::</span><span class="ruby-constant">Test</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">description</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000016"> <a name="M000016"></a><b>E</b>(message = nil, *kinds, &block) </div> <div class="description"> <p> Asserts that one of the given kinds of exceptions is raised when the given block is executed. </p> <p> If the block raises an exception, then that exception is returned. </p> <p> Otherwise, nil is returned. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> <dt>kinds</dt><dd>Exception classes that must be raised by the given block. <p> If none are given, then StandardError is assumed (similar to how a plain ‘rescue’ statement without any arguments catches StandardError). </p> </dd> </dl> <h4>Examples</h4> <pre> # no exceptions specified: E { } # fails E { raise } # passes # single exception specified: E( ArgumentError ) { raise ArgumentError } E( "argument must be invalid", ArgumentError ) { raise ArgumentError } # multiple exceptions specified: E( SyntaxError, NameError ) { eval "..." } E( "string must compile", SyntaxError, NameError ) { eval "..." } </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000016_source')" id="l_M000016_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L352" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000016_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 352</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">E</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_raise</span> <span class="ruby-identifier">:assert</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000017"> <a name="M000017"></a><b>E!</b>(message = nil, *kinds, &block) </div> <div class="description"> <p> Asserts that one of the given kinds of exceptions is not raised when the given block is executed. </p> <p> If the block raises an exception, then that exception is returned. </p> <p> Otherwise, nil is returned. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> <dt>kinds</dt><dd>Exception classes that must not be raised by the given block. <p> If none are given, then StandardError is assumed (similar to how a plain ‘rescue’ statement without any arguments catches StandardError). </p> </dd> </dl> <h4>Examples</h4> <pre> # no exceptions specified: E! { } # passes E! { raise } # fails # single exception specified: E!( ArgumentError ) { raise ArgumentError } # fails E!( "argument must be invalid", ArgumentError ) { raise ArgumentError } # multiple exceptions specified: E!( SyntaxError, NameError ) { eval "..." } E!( "string must compile", SyntaxError, NameError ) { eval "..." } </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000017_source')" id="l_M000017_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L394" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000017_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 394</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">E!</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_raise</span> <span class="ruby-identifier">:negate</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000018"> <a name="M000018"></a><b>E?</b>(message = nil, *kinds, &block) </div> <div class="description"> <p> Returns true if one of the given kinds of exceptions is raised when the given block is executed. Otherwise, returns false. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>This parameter is optional and completely ignored. </dd> <dt>kinds</dt><dd>Exception classes that must be raised by the given block. <p> If none are given, then StandardError is assumed (similar to how a plain ‘rescue’ statement without any arguments catches StandardError). </p> </dd> </dl> <h4>Examples</h4> <pre> # no exceptions specified: E? { } # => false E? { raise } # => true # single exception specified: E?( ArgumentError ) { raise ArgumentError } # => true # multiple exceptions specified: E?( SyntaxError, NameError ) { eval "..." } # => true </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000018_source')" id="l_M000018_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L429" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000018_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 429</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">E?</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_raise</span> <span class="ruby-identifier">:sample</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000015"> <a name="M000015"></a><b>F?</b>(message = nil, &block) </div> <div class="description"> <p> Returns true if the result of the given block is either nil or false. Otherwise, returns false. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>This parameter is optional and completely ignored. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: F? { true } # => false F? { false } # => true F? { nil } # => true # message specified: F?( "computers do not doublethink" ) { 2 + 2 == 5 } # => true </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000015_source')" id="l_M000015_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L309" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000015_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 309</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">F?</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">not</span> <span class="ruby-constant">T?</span> <span class="ruby-identifier">message</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000022"> <a name="M000022"></a><b>S</b>(*message) </div> <div class="description"> <p> Adds the given message to the report inside the section of the currently running test. </p> <p> You can think of “S” as “say” or “status”. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Objects to be added to the report. </dd> </dl> <h4>Examples</h4> <pre> S "establishing connection..." S "beginning calculation...", Math::PI, [1, 2, 3, ['a', 'b', 'c']] </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000022_source')" id="l_M000022_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L544" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000022_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 544</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S</span> <span class="ruby-operator">*</span><span class="ruby-identifier">message</span> <span class="ruby-ivar">@exec_trace</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">message</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000012"> <a name="M000012"></a><b>T</b>(message = nil, &block) </div> <div class="description"> <p> Asserts that the result of the given block is neither nil nor false and returns that result. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: T { true } # passes T { false } # fails T { nil } # fails # message specified: T( "computers do not doublethink" ) { 2 + 2 != 5 } # passes </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L229" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000012_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 229</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">T</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_yield</span> <span class="ruby-identifier">:assert</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000013"> <a name="M000013"></a><b>T!</b>(message = nil, &block) </div> <div class="description"> <p> Asserts that the result of the given block is either nil or false and returns that result. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>Optional message to show in the report if this assertion fails. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: T! { true } # fails T! { false } # passes T! { nil } # passes # message specified: T!( "computers do not doublethink" ) { 2 + 2 == 5 } # passes </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000013_source')" id="l_M000013_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L255" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000013_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 255</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">T!</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_yield</span> <span class="ruby-identifier">:negate</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000014"> <a name="M000014"></a><b>T?</b>(message = nil, &block) </div> <div class="description"> <p> Returns true if the result of the given block is neither nil nor false. Otherwise, returns false. </p> <h4>Parameters</h4> <dl> <dt>message</dt><dd>This parameter is optional and completely ignored. </dd> </dl> <h4>Examples</h4> <pre> # no message specified: T? { true } # => true T? { false } # => false T? { nil } # => false # message specified: T?( "computers do not doublethink" ) { 2 + 2 != 5 } # => true </pre> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000014_source')" id="l_M000014_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L280" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000014_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 280</span> <span class="ruby-keyword kw">def</span> <span class="ruby-constant">T?</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-identifier">assert_yield</span> <span class="ruby-identifier">:sample</span>, <span class="ruby-identifier">message</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000023"> <a name="M000023"></a><b>run</b>(continue = true) </div> <div class="description"> <p> Executes all tests defined thus far and stores the results in <a href="Dfect.html#report">report</a>. </p> <h4>Parameters</h4> <dl> <dt>continue</dt><dd>If true, results from previous executions will not be cleared. </dd> </dl> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000023_source')" id="l_M000023_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L556" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000023_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 556</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span> <span class="ruby-identifier">continue</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-comment cmt"># clear previous results</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">continue</span> <span class="ruby-ivar">@exec_stats</span>.<span class="ruby-identifier">clear</span> <span class="ruby-ivar">@exec_trace</span>.<span class="ruby-identifier">clear</span> <span class="ruby-ivar">@test_stack</span>.<span class="ruby-identifier">clear</span> <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># make new results</span> <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:stop_dfect_execution</span>) { <span class="ruby-identifier">execute</span> } <span class="ruby-comment cmt"># print new results</span> <span class="ruby-identifier">puts</span> <span class="ruby-ivar">@report</span>.<span class="ruby-identifier">to_yaml</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:quiet</span>] <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> <div class="method"> <div class="title" id="M000024"> <a name="M000024"></a><b>stop</b>() </div> <div class="description"> <p> Stops the execution of the <a href="Dfect.html#M000023">run</a> method or raises an exception if that method is not currently executing. </p> </div> <div class="sourcecode"> <p class="source-link"> Source: <a href="javascript:toggleSource('M000024_source')" id="l_M000024_source">show</a> | <a href="http://github.com/sunaku/dfect/blob/147e36e24957caf3763b5e28f7040f623e275625/lib/dfect.rb#L575" target="_blank" class="github_url">on GitHub</a> </p> <div id="M000024_source" class="dyn-source"> <pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 575</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span> <span class="ruby-identifier">throw</span> <span class="ruby-identifier">:stop_dfect_execution</span> <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> </div> </div> </body> </html>