<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>danwin.com &#187; testing</title>
	<atom:link href="https://danwin.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>https://danwin.com</link>
	<description>Words, photos, and code by Dan Nguyen. The &#039;g&#039; is mostly silent.</description>
	<lastBuildDate>Thu, 21 Nov 2019 12:29:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.39</generator>
	<item>
		<title>Ruby MiniTest Cheat Sheet, Unit and Spec reference</title>
		<link>https://danwin.com/2013/03/ruby-minitest-cheat-sheet/</link>
		<comments>https://danwin.com/2013/03/ruby-minitest-cheat-sheet/#comments</comments>
		<pubDate>Fri, 29 Mar 2013 21:19:00 +0000</pubDate>
		<dc:creator><![CDATA[Dan]]></dc:creator>
				<category><![CDATA[works]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">https://danwin.com/?p=2406</guid>
		<description><![CDATA[<p>Ruby&#8217;s standard testing suite, MiniTest, is in dire need of a quick-and-handy reference for its syntax. I&#8217;ve put one together comparing the unit syntax (assert/refute) and the spec syntax (must/wont). You can see it below or download the Google Spreadsheet I made and roll your own sheet (HTML, XLS) Test syntax Unit Spec Arguments Examples [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://danwin.com/2013/03/ruby-minitest-cheat-sheet/">Ruby MiniTest Cheat Sheet, Unit and Spec reference</a> appeared first on <a rel="nofollow" href="https://danwin.com">danwin.com</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Ruby&#8217;s standard testing suite, <a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/rdoc/MiniTest.html">MiniTest</a>, is in dire need of a quick-and-handy reference for its syntax. I&#8217;ve put one together comparing the <code>unit</code> syntax (assert/refute) and the <code>spec</code> syntax (must/wont). You can see it below or download the Google Spreadsheet I made and roll your own sheet (<a href="https://docs.google.com/spreadsheet/pub?key=0At3Q3D3lDxXcdGFRUHA1UnlyWm9ONWlkZU9oYmNzZlE&amp;output=html">HTML</a>, <a href="https://docs.google.com/spreadsheet/pub?key=0At3Q3D3lDxXcdGFRUHA1UnlyWm9ONWlkZU9oYmNzZlE&#038;output=xls">XLS</a>) </p>
<h3 id="test_syntax">Test syntax</h3>
<style>
</style>
<table class="table table-striped table-bordered vert">
<thead>
<tr>
<th>Unit</th>
<th>Spec</th>
<th>Arguments</th>
<th>Examples</th>
</tr>
</thead>
<tbody>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_empty<br />
refute_empty<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_empty<br />
wont_be_empty<br />
		  </code>
		</td>
<td>
		  <code><br />
obj, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_empty []</code><br /><code class="br">refute_empty [1,2,3]</code><br /><code class="br">[].must_be_empty</code><br /><code class="br">[1,2,3].wont_be_empty</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_equal<br />
refute_equal<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_equal<br />
wont_equal<br />
		  </code>
		</td>
<td>
		  <code><br />
exp, act, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_equal 2, 2</code><br /><code class="br">refute_equal 2,1</code><br /><code class="br">2.must_equal 2</code><br /><code class="br">2.wont_equal 1</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_in_delta<br />
refute_in_delta<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_within_delta<br />
wont_be_within_delta<br />
		  </code>
		</td>
<td>
		  <code><br />
exp, act, dlt=0.001, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_in_delta 2012, 2010, 2</code><br /><code class="br">refute_in_delta 2012, 3012, 2</code><br /><code class="br">2012.must_be_within_delta 2010, 2</code><br /><code class="br">2012.wont_be_within_delta 3012, 2</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"></p>
<p>		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_close_to<br />
wont_be_close_to<br />
		  </code>
		</td>
<td>
		  <code><br />
act, dlt=0.001, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">2012.must_be_close_to 2010, 2</code><br /><code class="br">2012.wont_be_close_to 3012, 2</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_in_epsilon<br />
refute_in_epsilon<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_within_epsilon<br />
wont_be_within_epsilon<br />
		  </code>
		</td>
<td>
		  <code><br />
a, b, eps=0.001, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_in_epsilon 1.0, 1.02, 0.05</code><br /><code class="br">refute_in_epsilon 1.0, 1.06, 0.05</code><br /><code class="br">1.0.must_be_within_epsilon 1.02, 0.05</code><br /><code class="br">1.0.wont_be_within_epsilon 1.06, 0.05</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_includes<br />
refute_includes<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_include<br />
wont_include<br />
		  </code>
		</td>
<td>
		  <code><br />
collection, obj, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_includes [1, 2], 2</code><br /><code class="br">refute_includes [1, 2], 3</code><br /><code class="br">[1, 2].must_include 2</code><br /><code class="br">[1, 2].wont_include 3</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_instance_of<br />
refute_instance_of<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_instance_of<br />
wont_be_instance_of<br />
		  </code>
		</td>
<td>
		  <code><br />
klass, obj, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_instance_of String, &quot;bar&quot;</code><br /><code class="br">refute_instance_of String, 100</code><br /><code class="br">&quot;bar&quot;.must_be_instance_of String</code><br /><code class="br">100.wont_be_instance_of String</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_kind_of<br />
refute_kind_of<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_kind_of<br />
wont_be_kind_of<br />
		  </code>
		</td>
<td>
		  <code><br />
klass, obj, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_kind_of Numeric, 100</code><br /><code class="br">refute_kind_of Numeric, &quot;bar&quot;</code><br /><code class="br">100.must_be_kind_of Numeric</code><br /><code class="br">&quot;bar&quot;.wont_be_kind_of Numeric</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_match<br />
refute_match<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_match<br />
wont_match<br />
		  </code>
		</td>
<td>
		  <code><br />
exp, act, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_match /\d/, &quot;42&quot;</code><br /><code class="br">refute_match /\d/, &quot;foo&quot;</code><br /><code class="br">&quot;42&quot;.must_match /\d/        </code><br /><code class="br">&quot;foo&quot;.wont_match /\d/</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_nil<br />
refute_nil<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_nil<br />
wont_be_nil<br />
		  </code>
		</td>
<td>
		  <code><br />
obj, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_nil [].first</code><br /><code class="br">refute_nil [1].first</code><br /><code class="br">[].first.must_be_nil</code><br /><code class="br">[1].first.wont_be_nil</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_operator<br />
refute_operator<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be<br />
wont_be<br />
		  </code>
		</td>
<td>
		  <code><br />
o1, op, o2, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_operator 1, :&lt;, 2</code><br /><code class="br">refute_operator 1, :&gt;, 2</code><br /><code class="br">1.must_be :&lt;, 2</code><br /><code class="br">1.wont_be :&gt;, 2</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_output<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_output<br />
		  </code>
		</td>
<td>
		  <code><br />
stdout = nil, stderr = nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_output(&quot;hi\n&quot;){ puts &quot;hi&quot; }</code><br /><code class="br">Proc.new{puts &quot;hi&quot;}.must_output &quot;hi\n&quot;</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_raises<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_raise<br />
		  </code>
		</td>
<td>
		  <code><br />
*exp<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_raises(NoMethodError){ nil! }</code><br /><code class="br">Proc.new{nil!}.must_raise NoMethodError</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_respond_to<br />
refute_respond_to<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_respond_to<br />
wont_respond_to<br />
		  </code>
		</td>
<td>
		  <code><br />
obj, meth, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_respond_to &quot;foo&quot;,:empty?</code><br /><code class="br">refute_respond_to 100, :empty?</code><br /><code class="br">&quot;foo&quot;.must_respond_to  :empty?</code><br /><code class="br">100.wont_respond_to :empty?</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_same<br />
refute_same<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_same_as<br />
wont_be_same_as<br />
		  </code>
		</td>
<td>
		  <code><br />
exp, act, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_same :foo, :foo</code><br /><code class="br">refute_same  ['foo'], ['foo']</code><br /><code class="br">:foo.must_be_same_as :foo</code><br /><code class="br">['foo'].wont_be_same_as ['foo']</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_silent<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_be_silent<br />
		  </code>
		</td>
<td>
		  <code><br />
-<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_silent{ 1 + 1 }</code><br /><code class="br">Proc.new{ 1 + 1}.must_be_silent</code><br /></p>
</td>
</tr>
<tr>
<td class="exp">
		  <code class="large br"><br />
assert_throws<br />
		  </code>
		</td>
<td class="exp">
		  <code class="large br"><br />
must_throw<br />
		  </code>
		</td>
<td>
		  <code><br />
sym, msg=nil<br />
		  </code>
		</td>
<td>
<p><code class="br">assert_throws(:up){ throw :up}</code><br /><code class="br">Proc.new{throw :up}.must_throw :up</code><br /></p>
</td>
</tr>
</tbody>
</table>
<h3 id="test-setup">Test Setup</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Unit</th>
<th>Spec</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>setup()</code></td>
<td><code>before(type = nil, &#038;block)</code></td>
</tr>
<tr>
<td><code>teardown()</code></td>
<td><code>after(type = nil, &#038;block)</code></td>
</tr>
</tbody>
</table>
<h3 id="mocks">Mocks</h3>
<p>via <a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/mock/rdoc/MiniTest/Mock.html" title="Class: MiniTest::Mock (Ruby 2.0)">MiniTest::Mock</a></p>
<ul>
<li><code>expect(name, retval, args=[])</code> &ndash;	Expect that method name is called, optionally with args or a blk, and returns retval.
<p>Example:</p>
<pre>
@mock.expect(:meaning_of_life, 42)
@mock.meaning_of_life # => 42

@mock.expect(:do_something_with, true, [some_obj, true])
@mock.do_something_with(some_obj, true) # => true

@mock.expect(:do_something_else, true) do |a1, a2|
   a1 == "buggs" &#038;&#038; a2 == :bunny
end
</pre>
</li>
<li><code>verify</code> &ndash; Verify that all methods were called as expected. Raises MockExpectationError if the mock object was not called as expected.
</li>
</ul>
<h3 id="other_syntax">Other syntax</h3>
<ul>
<li><code>def flunk(msg=nil)</code></li>
<li><code>def pass(msg=nil)</code></li>
<li><code>def skip(msg=nil, bt=caller)</code></li>
<li><code>def it (desc="anonymous", &#038;block)</code></li>
<li><code>i_suck_and_my_tests_are_order_dependent!()</code> &ndash; Call this at the top of your tests when you absolutely positively need to have ordered tests. <strong>In doing so, youâ€™re admitting that you suck and your tests are weak.</strong> (<a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/unit/rdoc/MiniTest/Unit/TestCase.html" title="Class: MiniTest::Unit::TestCase (Ruby 2.0)">TestCase public class method</a>)</li>
<li><code>parallelize_me!()</code> &ndash; Call this at the top of your tests when you want to run your tests in parallel. <strong>In doing so, youâ€™re admitting that you rule and your tests are awesome.</strong>
</li>
<li><code>make_my_diffs_pretty!()</code> &ndash; Make diffs for this TestCase use pretty_inspect so that diff in assert_equal can be more details. NOTE: this is much slower than the regular inspect but much more usable for complex objects.
</li>
</ul>
<h3 id="tutorials">Tutorials</h3>
<ul>
<li><a href="http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html">A MiniTest::Spec Tutorial: Elegant Spec-Style Testing, by Peter Cooper </a></li>
<li><a href="http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9">Minimalicious testing in Ruby 1.9 with MiniTest, by Arvid Anderson</a></li>
<li><a href="http://mattsears.com/articles/2011/12/10/minitest-quick-reference">Minitest Quick Reference, by Matt Sears</a></li>
</ul>
<h3 id="reference">Reference</h3>
<ul>
<li><a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/rdoc/MiniTest.html">MiniTest&#8217;s official readme</a></li>
<li><a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/spec/rdoc/">Ruby 2.0 Rdocs for MiniTest::Spec</a></li>
<li><a href="http://www.ruby-doc.org/stdlib-2.0/libdoc/minitest/unit/rdoc/">Ruby 2.0 Rdocs for MiniTest::Unit</a></li>
<li><a href="https://github.com/seattlerb/minitest">MiniTest on Github</a></li>
<li>My <a href="https://docs.google.com/spreadsheet/pub?key=0At3Q3D3lDxXcdGFRUHA1UnlyWm9ONWlkZU9oYmNzZlE&amp;output=html">Google Spreadsheet of MiniTest calls, as Excel</a></li>
<li>StackOverflow:<a href="http://stackoverflow.com/questions/7211086/how-do-i-stub-things-in-minitest"> How do I mock things in MiniTest?</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://danwin.com/2013/03/ruby-minitest-cheat-sheet/">Ruby MiniTest Cheat Sheet, Unit and Spec reference</a> appeared first on <a rel="nofollow" href="https://danwin.com">danwin.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://danwin.com/2013/03/ruby-minitest-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
