<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Floehopper: Tag testing</title>
    <link>http://blog.floehopper.org/articles/tag/testing?tag=testing</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts on the bergy bits of life</description>
    <item>
      <title>Mocha Release 0.9.1</title>
      <description>&lt;h2&gt;Release Notes&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;Fixed bug #21465 &amp;#8211; expects &amp;#38; stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string.&lt;/li&gt;
		&lt;li&gt;By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563.&lt;/li&gt;
		&lt;li&gt;Fix bug #21563 &amp;#8211; stubbing &amp;#8216;verified?&amp;#8217; method is unsafe. Instance method names on the Mock class should be more obscure.&lt;/li&gt;
		&lt;li&gt;Performance improvement. StubbaExampleTest goes twice as fast on my local machine.&lt;/li&gt;
		&lt;li&gt;Added primitive performance test to default rake task.&lt;/li&gt;
		&lt;li&gt;Fix format of case statements which don&amp;#8217;t work in Ruby 1.9 and make others consistent.&lt;/li&gt;
		&lt;li&gt;There is no point in running (potentially expensive) checks if configuration is set to allow such checks to fail. This is a relatively quick fix in response to Chris McGrath&amp;#8217;s performance problems.&lt;/li&gt;
		&lt;li&gt;Fix for bug #21161 &amp;#8211; &amp;#8216;uninitialized constant Deprecation in stubba.rb&amp;#8217;.&lt;/li&gt;
		&lt;li&gt;It&amp;#8217;s more readable to talk about &amp;#8216;once&amp;#8217; and &amp;#8216;twice&amp;#8217; rather than &amp;#8216;1 time&amp;#8217; and &amp;#8216;2 times&amp;#8217;.&lt;/li&gt;
		&lt;li&gt;Fix bug #20883 &amp;#8211; never should raise when called to prevent follow up errors. Fail fast when there are no matching invokable expectations and handle the stub_everything case sensibly. This might not be entirely backwards compatible, but I think the benefits outweigh the risks. The most likely change is that a test that was already failing will now fail faster, which doesn&amp;#8217;t seem so awful.&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Sat, 30 Aug 2008 16:48:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:be9e6b4d-d778-45cb-a779-7ff68a457eb3</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2008/08/30/mocha-release-0-9-1</link>
      <category>mocha_release</category>
      <category>mocha</category>
      <category>mock</category>
      <category>stub</category>
      <category>ruby</category>
      <category>testing</category>
      <category>tdd</category>
    </item>
    <item>
      <title>Vim Learning Curve</title>
      <description>&lt;p&gt;Because I&amp;#8217;ve been doing a lot of &lt;a href="http://blog.floehopper.org/articles/2008/03/13/remote-pair-programming"&gt;remote pair programming&lt;/a&gt; using &lt;a href="http://www.vim.org/"&gt;vim&lt;/a&gt; and &lt;a href="http://www.gnu.org/software/screen/"&gt;screen&lt;/a&gt;,  I&amp;#8217;ve been making a real effort to improve my vim skills in order to be more productive and feel like I&amp;#8217;ve made some progress. &lt;a href="http://blog.seagul.co.uk"&gt;Chris&lt;/a&gt; has rightly suggested that the only way to really improve is to make vim your editor of choice even when not remote pairing, so that&amp;#8217;s what I&amp;#8217;ve been trying to do. I&amp;#8217;ve come across a few useful but random bits and pieces which I thought I&amp;#8217;d record in case they were useful to anyone else&amp;#8230;&lt;/p&gt;


	&lt;h2&gt;Textile&lt;/h2&gt;


	&lt;p&gt;I&amp;#8217;m using a &lt;a href="http://rubychan.de/share/textile.vim"&gt;vim syntax file&lt;/a&gt; for &lt;a href="http://hobix.com/textile/"&gt;Textile&lt;/a&gt; written by Kornelius Kalnbach to write this article.&lt;/p&gt;


	&lt;h2&gt;svn blame&lt;/h2&gt;


	&lt;p&gt;I&amp;#8217;ve found Tammer Saleh&amp;#8217;s &lt;a href="http://tammersaleh.com/posts/quick-vim-svn-blame-snippet"&gt;key mapping&lt;/a&gt; for &lt;a href="http://svnbook.red-bean.com/en/1.0/re02.html"&gt;svn blame&lt;/a&gt; useful&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  vmap gl :&amp;lt;C-U&amp;gt;!svn blame &amp;lt;C-R&amp;gt;=expand(&amp;quot;%:p&amp;quot;) &amp;lt;CR&amp;gt; \| sed -n &amp;lt;C-R&amp;gt;=line(&amp;quot;'&amp;lt;&amp;quot;) &amp;lt;CR&amp;gt;,&amp;lt;C-R&amp;gt;=line(&amp;quot;'&amp;gt;&amp;quot;) &amp;lt;CR&amp;gt;p &amp;lt;CR&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I decided to invest a bit of time understanding how it worked and broke it down as follows&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  # key mapping for visual mode
  vmap gl
  # remove all characters between the cursor position and the beginning of the line
  :&amp;lt;C-U&amp;gt;
  # current file with full path
  &amp;lt;C-R&amp;gt;=expand(&amp;quot;%:p&amp;quot;) &amp;lt;CR&amp;gt;
  # pipe std out to sed which only outputs line N to line M
  \| sed -n N,M
  # line number of first line of selection
  &amp;lt;C-R&amp;gt;=line(&amp;quot;'&amp;lt;&amp;quot;) &amp;lt;CR&amp;gt;
  # line number of last line of selection
  &amp;lt;C-R&amp;gt;=line(&amp;quot;'&amp;gt;&amp;quot;) &amp;lt;CR&amp;gt;
  # print output
  p &amp;lt;CR&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h2&gt;Search &amp;#38; Replace&lt;/h2&gt;


	&lt;p&gt;At the end of last week, &lt;a href="http://blog.seagul.co.uk"&gt;Chris&lt;/a&gt; &amp;#38; I found out from Ibrahim Ahmed&amp;#8217;s blog how to &lt;a href="http://www.ibrahim-ahmed.com/2008/01/find-and-replace-in-multiple-files-in.html"&gt;search and replace across multiple files&lt;/a&gt;...&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  # select file on which to operate
  :args path/with/wildcards
  # find pattern, replace with replacement, and save file
  :argdo %s/pattern/replacement/ge | update&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h2&gt;vimdiff&lt;/h2&gt;


	&lt;p&gt;&lt;a href="http://www.vim.org/htmldoc/diff.html"&gt;&lt;code&gt;vimdiff&lt;/code&gt;&lt;/a&gt; seems like a nice tool, but unfortunately it doesn&amp;#8217;t immediately play well with &lt;a href="http://svnbook.red-bean.com/en/1.0/re09.html"&gt;&lt;code&gt;svn diff&lt;/code&gt;&lt;/a&gt; and its &lt;code&gt;--diff-cmd&lt;/code&gt; option. There seem to be a couple of alternatives: (a) write a &lt;a href="http://svn.haxx.se/users/archive-2005-04/1048.shtml"&gt;wrapper script for &lt;code&gt;vimdiff&lt;/code&gt;&lt;/a&gt; which works with &lt;code&gt;--diff-cmd&lt;/code&gt;; or (b) write a &lt;a href="http://erik.thauvin.net/blog/comments.jsp?postid=1024"&gt;script which uses &lt;code&gt;svn cat&lt;/code&gt; and then calls &lt;code&gt;vimdiff&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


	&lt;h2&gt;Test::Unit&lt;/h2&gt;


	&lt;p&gt;One of the things I really want to be able to do, is run Ruby &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; tests and view the output, so I can jump to the line where an assertion failed. I haven&amp;#8217;t managed to find anything suitable on the web, so here&amp;#8217;s my first attempt&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  function! Ruby_run_tests()
    let results = tempname()
    set splitbelow
    silent execute &amp;quot;:! ruby % &amp;gt; &amp;quot; . results . &amp;quot; 2&amp;gt;&amp;amp;1 &amp;quot;
    silent execute &amp;quot;:10 sview &amp;quot; . results
  endfunction

  map &amp;lt;silent&amp;gt; &amp;lt;F7&amp;gt; :call Ruby_run_tests()&amp;lt;cr&amp;gt;
  imap &amp;lt;silent&amp;gt; &amp;lt;F7&amp;gt; &amp;lt;ESC&amp;gt;&amp;lt;F7&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m sure this isn&amp;#8217;t the best way of doing it, but when you put this in your vimrc file, pressing the &lt;code&gt;F7&lt;/code&gt; key runs the current file using Ruby and pipes the results to a temporary file. This temporary file is opened in a read-only window 10 lines high at the bottom of the screen. By moving the cursor onto the relevant line of any stack trace, you can then use &amp;#8220;goto file&amp;#8221; key sequence &lt;code&gt;gf&lt;/code&gt; to goto the failing assertion. Although for some reason this only seems to work the first time round for me.&lt;/p&gt;


	&lt;p&gt;Ideally I&amp;#8217;d like to be able to do the equivalent of &amp;#8220;run focussed test&amp;#8221; in &lt;a href="http://macromates.com/"&gt;TextMate&lt;/a&gt;, which should be quite straightforward, but that&amp;#8217;ll have to wait for another day.&lt;/p&gt;


	&lt;p&gt;In the meantime, I&amp;#8217;d love to hear from anyone else who has useful vim tricks for &lt;a href="http://www.ruby-lang.org/"&gt;Ruby&lt;/a&gt; development. I&amp;#8217;ll be bookmarking any useful links I find on &lt;a href="http://del.icio.us/jamesthecat/vim"&gt;del.icio.us&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Sat, 12 Jul 2008 22:52:35 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c7afcd35-0c86-40a8-88c1-d0485fbc2477</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2008/07/12/vim-learning-curve</link>
      <category>vim</category>
      <category>svn</category>
      <category>diff</category>
      <category>blame</category>
      <category>syntax</category>
      <category>textile</category>
      <category>search</category>
      <category>replace</category>
      <category>testing</category>
      <category>textmate</category>
    </item>
    <item>
      <title>Mocha 0.9 Released</title>
      <description>&lt;p&gt;There&amp;#8217;s been quite a bit of work going on in &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; over recent months, but a release is long overdue. The &lt;span class="caps"&gt;API&lt;/span&gt; is now pretty stable and so this release jumps from version 0.5 to 0.9. Much of the work has been refactoring Mocha&amp;#8217;s internals to support new features and make the code more maintainable.&lt;/p&gt;


	&lt;p&gt;Before attempting the refactoring, extensive acceptance tests were added. One of the benefits of this is that it should now be easier to write new acceptance tests if you want to suggest new features or illustrate a bug ;-)&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s a quick summary of the changes in the release. I&amp;#8217;ll try to post some code examples here in the near future.&lt;/p&gt;


	&lt;h2&gt;Ordering constraints&lt;/h2&gt;


	&lt;p&gt;Based on the &lt;a href="http://jmock.org/"&gt;JMock&lt;/a&gt; constraints with the same names&amp;#8230;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Added &amp;#8220;sequences&amp;#8221; for constraining the order of expected invocations. See &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Standalone.html#M000008"&gt;Standalone#sequence&lt;/a&gt; and &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000049"&gt;Expectation#in_sequence&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Added &amp;#8220;states&amp;#8221; for constraining the order of expected invocations. See &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Standalone.html#M000009"&gt;Standalone#states&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000047"&gt;Expectation#then&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000048"&gt;Expectation#when&lt;/a&gt; and &lt;a href="http://mocha.rubyforge.org/classes/Mocha/StateMachine.html"&gt;StateMachine&lt;/a&gt;.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Configurable warnings or errors&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;When a method on a non-public method is stubbed&lt;/li&gt;
		&lt;li&gt;When a method on a non-existent method is stubbed&lt;/li&gt;
		&lt;li&gt;When a method on a non-mock object is stubbed (partial mocking)&lt;/li&gt;
		&lt;li&gt;When a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;See &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Configuration.html"&gt;Configuration&lt;/a&gt; for more details.&lt;/p&gt;


	&lt;h2&gt;Improved error messages&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;A more readable and complete list of unsatisfied expectations, satisfied expectations and state machines.&lt;/li&gt;
		&lt;li&gt;Display more sensible failure message for any_instance expectations.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Parameter matchers&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;New to this release: &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000024"&gt;optionally&lt;/a&gt; (allows matching of optional parameters if available), &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000027"&gt;yaml_equivalent&lt;/a&gt; (allows matching of &lt;span class="caps"&gt;YAML&lt;/span&gt; that represents the specified object), &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000026"&gt;responds_with&lt;/a&gt; (tests the quack not the duck).&lt;/li&gt;
		&lt;li&gt;Nesting of matchers is now supported.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Syntax shortcut&lt;/h2&gt;


	&lt;p&gt;An optional block can be passed into the &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Standalone.html#M000005"&gt;Standalone#mock&lt;/a&gt; method. The block is evaluated in the context of the new mock instance and can be used as a shortcut to set up expectations.&lt;/p&gt;


	&lt;h2&gt;Ruby &amp;#38; Rails compatibility&lt;/h2&gt;


	&lt;p&gt;Tested with Ruby 1.8.4, 1.8.5, 1.8.6 &amp;#38; 1.9. All related bugs and warnings believed to be fixed.&lt;/p&gt;


	&lt;p&gt;Tested with Rails 1.2.3 &amp;#38; Rails 2.1.0.&lt;/p&gt;


	&lt;h2&gt;Deprecation&lt;/h2&gt;


	&lt;p&gt;There is no longer any need to have a &amp;#8220;require &amp;#8216;stubba&amp;#8217;&amp;#8221; statement in your code. A deprecation warning has been added to this effect, because the file will be removed in a future release.&lt;/p&gt;


	&lt;h2&gt;Bug fixes&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=18914&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;18914 in revision 296&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=18917&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;18917 in revision 295&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=18336&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;18336 in revision 287&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=17835&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;17835 in revision 255&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=17412&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;17412 in revision 242&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=15977&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;15977 in revision 198&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://rubyforge.org/tracker/index.php?func=detail&amp;#38;aid=11885&amp;#38;group_id=1917&amp;#38;atid=7477"&gt;11885 in revision 156&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Tue, 24 Jun 2008 19:14:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:22e0bfc7-8cd0-4d92-8e72-81397544c6a1</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2008/06/24/mocha-0-9-released</link>
      <category>mocha_release</category>
      <category>mocha</category>
      <category>mock</category>
      <category>release</category>
      <category>ruby</category>
      <category>stub</category>
      <category>testing</category>
      <category>jmock</category>
    </item>
    <item>
      <title>Nasty Ruby Bug Affecting Test::Unit</title>
      <description>&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;Some time ago, while I was pair-programming with him, &lt;a href="http://blog.seagul.co.uk"&gt;Chris&lt;/a&gt; alerted me to a &lt;a href="http://www.ruby-lang.org/"&gt;Ruby&lt;/a&gt; bug he&amp;#8217;d come across which was interfering with the diagnosis of a bug in our application. Since then I&amp;#8217;ve tried to find out more about it, but couldn&amp;#8217;t find much, so I&amp;#8217;ve done a bit of investigation and thought I&amp;#8217;d post it here in case it&amp;#8217;s useful to anyone else. The bug has long since been fixed, but I&amp;#8217;m sure there are still people our there with the &lt;a href="#affected-versions"&gt;affected versions&lt;/a&gt; of Ruby 1.8.6.&lt;/p&gt;


	&lt;h3 id="ruby-bug"&gt;Ruby bug&lt;/h3&gt;


	&lt;p&gt;As far as I understand it, the bug is in Ruby&amp;#8217;s &lt;a href="http://ruby-doc.org/core/classes/Kernel.html#M005958"&gt;&lt;code&gt;Kernel.at_exit&lt;/code&gt;&lt;/a&gt; hook. A call to &lt;a href="http://ruby-doc.org/core/classes/Kernel.html#M005956"&gt;&lt;code&gt;Kernel.exit(false)&lt;/code&gt;&lt;/a&gt; should cause the process to exit with an &lt;strong&gt;exit status of 1&lt;/strong&gt; indicating the process did not complete successfully. The bug means that calling &lt;a href="http://ruby-doc.org/core/classes/Kernel.html#M005956"&gt;&lt;code&gt;Kernel.exit(false)&lt;/code&gt;&lt;/a&gt; from within &lt;a href="http://ruby-doc.org/core/classes/Kernel.html#M005958"&gt;&lt;code&gt;Kernel.at_exit&lt;/code&gt;&lt;/a&gt; incorrectly causes the process to exit with an &lt;strong&gt;exit status of 0&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;The most relevant bug report is &lt;a href="http://rubyforge.org/tracker/?func=detail&amp;#38;atid=1698&amp;#38;aid=9300&amp;#38;group_id=426"&gt;#9300&lt;/a&gt; and the most relevant mailing list thread is made up of:- &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10746"&gt;[ruby-core:10746]&lt;/a&gt;, &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10748"&gt;[ruby-core:10748]&lt;/a&gt;, &lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10760"&gt;[ruby-core:10760]&lt;/a&gt;.&lt;/p&gt;


The fix seems to be in changeset 12126&amp;#8230;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;r12126 | nobu | 2007-03-23 16:53:42 +0000 (Fri, 23 Mar 2007) | 9 lines

* eval.c (ruby_cleanup): exit by SystemExit and SignalException in END
  block.  [ruby-core:10609]

* test/ruby/test_beginendblock.rb (test_should_propagate_exit_code):
  test for exit in END block.  [ruby-core:10760]

* test/ruby/test_beginendblock.rb (test_should_propagate_signaled):
  test for signal in END block.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 class="implications"&gt;Implications for Test::Unit &amp;#38; Rake::TestTask&lt;/h3&gt;


	&lt;p&gt;The &lt;a href="#ruby-bug"&gt;bug&lt;/a&gt; has some important consequences. &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;&lt;code&gt;Test::Unit&lt;/code&gt;&lt;/a&gt; makes use of this mechanism to report test failures. Unfortunately, the bug means that a &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;&lt;code&gt;Test::Unit&lt;/code&gt;&lt;/a&gt; process will always return an &lt;strong&gt;exit status of 0&lt;/strong&gt; even when there have been test failures.&lt;/p&gt;


From &lt;code&gt;test/unit.rb&lt;/code&gt;:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;at_exit&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="keyword"&gt;unless&lt;/span&gt; &lt;span class="global"&gt;$!&lt;/span&gt; &lt;span class="punct"&gt;||&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;run?&lt;/span&gt;
    &lt;span class="ident"&gt;exit&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;AutoRunner&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;run&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This in turn means that a &lt;a href="http://rake.rubyforge.org/classes/Rake/TestTask.html"&gt;&lt;code&gt;Rake::TestTask&lt;/code&gt;&lt;/a&gt; process will also always return an &lt;strong&gt;exit status of 0&lt;/strong&gt; even when there have been test failures. This is significant, because many &lt;a href="http://martinfowler.com/articles/continuousIntegration.html"&gt;continuous integration&lt;/a&gt; systems rely on &lt;a href="http://rake.rubyforge.org/classes/Rake/TestTask.html"&gt;&lt;code&gt;Rake::TestTask&lt;/code&gt;&lt;/a&gt; processes returning an &lt;strong&gt;exit status of 1&lt;/strong&gt; to indicate that there have been test failures. Thus you will get false positive passing builds &amp;#8211; not good.&lt;/p&gt;


	&lt;h3 id="affected-versions"&gt;Affected versions of Ruby&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;ve built and installed a number of versions of Ruby and run tests on them to try to establish which ones are affected. Although they aren&amp;#8217;t comprehensive, here are the results&amp;#8230;&lt;/p&gt;


	&lt;table&gt;
		&lt;tr style="background:#ddd;"&gt;
			&lt;td&gt; affected? &lt;/td&gt;
			&lt;td&gt; version &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.4 (2005-12-24) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.5 (2006-08-25) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.5 (2007-03-16 patchlevel 37) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.5 (2008-03-03 patchlevel 115) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-02-17 patchlevel 0) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-03-16 patchlevel 2) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-03-19 patchlevel 4) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-22 patchlevel 5) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-22 patchlevel 6) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr style="color:red;"&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;Y&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-22 patchlevel 7) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-22 patchlevel 8) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-23 patchlevel 9) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-05-23 patchlevel 10) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.8.6 (2007-08-22 patchlevel 50) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td style="text-align:center;"&gt;&lt;code&gt;N&lt;/code&gt; &lt;/td&gt;
			&lt;td&gt; &lt;code&gt;ruby 1.9.0 (2007-11-28 patchlevel 0) [i686-darwin8.10.3]&lt;/code&gt; &lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;</description>
      <pubDate>Sat, 05 Apr 2008 00:10:06 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3aa53475-6a90-4cf6-915b-ff8804ff5d61</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2008/04/05/nasty-ruby-bug-affecting-test-unit</link>
      <category>ruby</category>
      <category>bug</category>
      <category>test</category>
      <category>unit</category>
      <category>exit</category>
      <category>code</category>
      <category>hook</category>
      <category>testing</category>
      <category>continuous</category>
      <category>integration</category>
    </item>
    <item>
      <title>Mock Object Injection</title>
      <description>&lt;p&gt;A few months back, in my &lt;a href="http://blog.floehopper.org/presentations/lrug-mock-objects-2007-07-09/"&gt;Introduction to Mock Objects talk&lt;/a&gt; at &lt;a href="http://lrug.org"&gt;&lt;span class="caps"&gt;LRUG&lt;/span&gt;&lt;/a&gt;, I talked about &amp;#8220;Mock Object Injection&amp;#8221;. At the time I described a number of different ways of replacing a production object with a &lt;a href="http://www.mockobjects.com"&gt;Mock Object&lt;/a&gt; using &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt;. I remember that at &lt;a href="http://lrug.org/meetings/2007/06/20/july-2007-meeting/"&gt;the meeting&lt;/a&gt;, &lt;a href="http://interblah.net/"&gt;James Adam&lt;/a&gt; (who has since joined the team at &lt;a href="http://www.reevoo.com"&gt;Reevoo&lt;/a&gt;) asked me why I didn&amp;#8217;t like the &lt;a href="#any-instance-stub-injection"&gt;Any Instance Stub Injection&lt;/a&gt; technique.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m not sure I gave him a very convincing response and I&amp;#8217;ve been meaning for ages to have a better go at explaining what I think are the pros and cons of each of the techniques I mentioned. Here&amp;#8217;s the list of techniques with the ones I like best at the top. I still haven&amp;#8217;t done a very good job, but I&amp;#8217;d be interested to hear what other people think so that I can try and improve my understanding.&lt;/p&gt;


	&lt;h3 id="constructor-injection"&gt;Constructor Injection&lt;/h3&gt;


	&lt;p&gt;The &lt;code&gt;ClassUnderTest&lt;/code&gt; allows its dependencies to be passed in as parameters to its constructor. A mock object is passed in as a replacement for the &amp;#8220;real&amp;#8221; collaborator. It may be convenient to specify the production collaborator as a default parameter value.&lt;/p&gt;


	&lt;h4&gt;Advantages&lt;/h4&gt;


	&lt;p&gt;The dependencies of the &lt;code&gt;ClassUnderTest&lt;/code&gt; are explicit.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;Can&amp;#8217;t think of any at the moment.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="attribute"&gt;@dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="comment"&gt;# use @dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="comment"&gt;# constructor parameter injection&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="parameter-injection"&gt;Parameter Injection&lt;/h3&gt;


	&lt;p&gt;The &lt;code&gt;ClassUnderTest&lt;/code&gt; allows its dependencies to be passed in as parameters to the method under test. A mock object is passed in as a replacement for the &amp;#8220;real&amp;#8221; collaborator. It may be convenient to specify the production collaborator as a default parameter value.&lt;/p&gt;


	&lt;h4&gt;Advantages&lt;/h4&gt;


	&lt;p&gt;The dependencies of the method under test are explicit.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;Can&amp;#8217;t think of any at the moment.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;local_dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# use local_dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="comment"&gt;# method parameter injection&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="stubbed-new-method-injection"&gt;Stubbed New Method Injection&lt;/h3&gt;


	&lt;p&gt;Use Mocha&amp;#8217;s &lt;a href="http://mocha.rubyforge.org/classes/Object.html#M000003"&gt;Object#stubs&lt;/a&gt; to temporarily replace &lt;code&gt;Collaborator#new&lt;/code&gt; with a stub implementation that returns a mock object.&lt;/p&gt;


	&lt;h4&gt;Advantages&lt;/h4&gt;


	&lt;p&gt;Better than &lt;a href="#any-instance-stub-injection"&gt;Any Instance Stub Injection&lt;/a&gt;, because you can have more control over different instances of &lt;code&gt;Collaborator&lt;/code&gt;.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;Dependencies of the &lt;code&gt;ClassUnderTest&lt;/code&gt; are hidden and not explicit.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;
      &lt;span class="attribute"&gt;@dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="comment"&gt;# use @dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="comment"&gt;# stubbed new method injection&lt;/span&gt;
  &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="writer-method-injection"&gt;Writer Method Injection&lt;/h3&gt;


	&lt;p&gt;Use an attribute writer method to replace the &amp;#8220;real&amp;#8221; collaborator with a mock object.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;The &lt;code&gt;ClassUnderTest&lt;/code&gt; has to unnecessarily expose a way to modify its internal state. The test is coupled to the implementation of the &lt;code&gt;ClassUnderTest&lt;/code&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="ident"&gt;attr_writer&lt;/span&gt; &lt;span class="symbol"&gt;:dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;
      &lt;span class="attribute"&gt;@dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="comment"&gt;# use @dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="comment"&gt;# writer method injection&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;collaborator&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="stubbed-private-method-injection"&gt;Stubbed Private Method Injection&lt;/h3&gt;


	&lt;p&gt;Use &lt;em&gt;partial mocking&lt;/em&gt; to temporarily replace a private builder method with a stubbed version of the method.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;The test is coupled to the implementation of the &lt;code&gt;ClassUnderTest&lt;/code&gt;. The partial mocking of the &lt;code&gt;instance_under_test&lt;/code&gt; means that the test is not testing a pristine instance of the &lt;code&gt;ClassUnderTest&lt;/code&gt;, but a modified one. It also means that the boundaries between test code and production code are less clear.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="ident"&gt;local_dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;build_collaborator&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
      &lt;span class="comment"&gt;# use local_dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="ident"&gt;private&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;build_collaborator&lt;/span&gt;
      &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="comment"&gt;# stubbed private method injection&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:build_collaborator&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="any-instance-stub-injection"&gt;Any Instance Stub Injection&lt;/h3&gt;


	&lt;p&gt;Use Mocha&amp;#8217;s &lt;a href="http://mocha.rubyforge.org/classes/Class.html#M000001"&gt;Class#any_instance&lt;/a&gt; method to temporarily replace the method on a collaborator with a stub method.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;The stubbed method is applied to &lt;strong&gt;all&lt;/strong&gt; instances of the collaborating class. If the &lt;code&gt;instance_under_test&lt;/code&gt; interacts with the stubbed method on more than one instance of the collaborating class, it isn&amp;#8217;t possible to specify different behaviour for the stubbed method on each instance. Even if the &lt;code&gt;instance_under_test&lt;/code&gt; only interacts with the stubbed method on one instance of the collaborating class, the test is specifying more stubbed behaviour than strictly necessary which could lead to false positives.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="ident"&gt;local_dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
      &lt;span class="keyword"&gt;return&lt;/span&gt; &lt;span class="ident"&gt;local_dependency&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_stuff&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="comment"&gt;# any_instance stub injection&lt;/span&gt;
  &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;any_instance&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:do_stuff&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;return&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;something useful&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="instance-variable-set-injection"&gt;Instance Variable Set Injection&lt;/h3&gt;


	&lt;p&gt;Use &lt;a href="http://www.ruby-doc.org/core/classes/Object.html#M000366"&gt;&lt;code&gt;Object#instance_variable_set&lt;/code&gt;&lt;/a&gt; to replace the reference to a collaborator with a mock object.&lt;/p&gt;


	&lt;h4&gt;Disadvantages&lt;/h4&gt;


	&lt;p&gt;The test is coupled to the implementation of the &lt;code&gt;ClassUnderTest&lt;/code&gt;. In particular the test is coupled to the supposedly private instance variable. In my opinion, it would be more honest to expose the instance variable by adding an attribute writer and using &lt;a href="#writer-method-injection"&gt;Writer Method Injection&lt;/a&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ClassUnderTest&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;
      &lt;span class="attribute"&gt;@dependency&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Collaborator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;do_something&lt;/span&gt;
      &lt;span class="comment"&gt;# use @dependency&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;collaborator&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;ClassUnderTest&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
  &lt;span class="comment"&gt;# instance_variable_set injection&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;instance_variable_set&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:@dependency&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;collaborator&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;instance_under_test&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;do_something&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 29 Nov 2007 12:17:48 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:7a475c05-12b4-448c-baaa-a5e5d1854f9b</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/11/29/mock-object-injection</link>
      <category>ruby</category>
      <category>mock</category>
      <category>object</category>
      <category>dependency</category>
      <category>injection</category>
      <category>collaborator</category>
      <category>testing</category>
    </item>
    <item>
      <title>Mock Commands, Stub Queries</title>
      <description>&lt;p&gt;&lt;a href="http://www.simplechatter.com"&gt;Zach Moazeni&lt;/a&gt; has just posted a &lt;a href="http://www.simplechatter.com/2007/8/3/mocha-and-forcing-verification"&gt;suggested patch&lt;/a&gt; for Mocha over on his blog. My understanding of the patch is that it means expectations are verified even when an assertion error occurs in the test. Here is his example&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;
  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Car&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;parts&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;[])&lt;/span&gt;
      &lt;span class="attribute"&gt;@parts&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;parts&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;start&lt;/span&gt;
      &lt;span class="ident"&gt;started&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;true&lt;/span&gt;
      &lt;span class="attribute"&gt;@parts&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;each&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;part&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;
        &lt;span class="comment"&gt;# commenting out for failure&lt;/span&gt;
        &lt;span class="comment"&gt;# started = started &amp;amp;&amp;amp; part.start&lt;/span&gt;
      &lt;span class="keyword"&gt;end&lt;/span&gt;

      &lt;span class="ident"&gt;started&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;SomeTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TestCase&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_start&lt;/span&gt;
      &lt;span class="ident"&gt;engine_mock&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;engine_mock&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
      &lt;span class="ident"&gt;car&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="ident"&gt;engine_mock&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;

      &lt;span class="ident"&gt;engine_mock&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:start&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;false&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="ident"&gt;assert&lt;/span&gt; &lt;span class="punct"&gt;!&lt;/span&gt;&lt;span class="ident"&gt;car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;start&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;ve had a friendly &amp;#38; useful conversation with Zach about it, but I&amp;#8217;m not convinced this is the right way to go. Using the &lt;a href="http://www.artima.com/weblogs/viewpost.jsp?thread=35578"&gt;one assertion per test&lt;/a&gt; school of thought, you can achieve the same goal by splitting the test into two so you get a test failure for the expectation and another for the assertion&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;
  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;SomeTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TestCase&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_should_start_engine&lt;/span&gt;
      &lt;span class="ident"&gt;engine&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;car&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;

      &lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:start&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

      &lt;span class="ident"&gt;car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;start&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_should_start_if_engine_starts&lt;/span&gt;
      &lt;span class="ident"&gt;engine&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;car&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;

      &lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:start&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;false&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

      &lt;span class="ident"&gt;assert&lt;/span&gt; &lt;span class="punct"&gt;!&lt;/span&gt;&lt;span class="ident"&gt;car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;start&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Something that makes the example less suitable for mocking is that the Car#start method is both &lt;a href="http://www.jmock.org/yoga.html"&gt;a command and a query&lt;/a&gt;. If you separate the two, testing with mocks might be easier&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;
  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Car&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;initialize&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;parts&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;[])&lt;/span&gt;
      &lt;span class="attribute"&gt;@parts&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;parts&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;start&lt;/span&gt;
      &lt;span class="attribute"&gt;@parts&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;each&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;part&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;part&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;start&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;started?&lt;/span&gt;
      &lt;span class="attribute"&gt;@parts&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;all?&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;part&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;part&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;started?&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;SomeOtherTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Test&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Unit&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TestCase&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_should_start_engine&lt;/span&gt;
      &lt;span class="ident"&gt;engine&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;car&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;

      &lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:start&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

      &lt;span class="ident"&gt;car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;start&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_should_not_be_started_if_engine_is_started&lt;/span&gt;
      &lt;span class="ident"&gt;engine&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;car&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;

      &lt;span class="ident"&gt;engine&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:started?&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;false&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

      &lt;span class="ident"&gt;assert&lt;/span&gt; &lt;span class="punct"&gt;!&lt;/span&gt;&lt;span class="ident"&gt;car&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;started?&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;d be interested to know what other people think&amp;#8230;&lt;/p&gt;


	&lt;p&gt;One thing I do agree with Zach about is that submitting a suggested patch to an open source project is a great way of initiating a constructive conversation.&lt;/p&gt;</description>
      <pubDate>Fri, 03 Aug 2007 10:10:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:22926b95-53c4-472e-9a92-4b08f504f9b7</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/08/03/mock-commands-stub-queries</link>
      <category>mocha</category>
      <category>mock</category>
      <category>stub</category>
      <category>testing</category>
      <category>assert</category>
      <category>verify</category>
      <category>expectation</category>
      <category>command</category>
      <category>query</category>
    </item>
    <item>
      <title>Mock Objects in Ruby</title>
      <description>&lt;p&gt;As &lt;a href="http://blog.floehopper.org/articles/2007/07/10/lrug-mocking-talk"&gt;promised&lt;/a&gt; I&amp;#8217;ve finally got round to making the &lt;a href="http://meyerweb.com/eric/tools/s5/"&gt;S5&lt;/a&gt; slides of my &lt;a href="http://www.lrug.org/meetings/2007/06/20/july-2007-meeting/"&gt;&lt;span class="caps"&gt;LRUG&lt;/span&gt; talk&lt;/a&gt; available &lt;a href="http://blog.floehopper.org/presentations/lrug-mock-objects-2007-07-09/"&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;You can use &lt;a href="http://meyerweb.com/eric/tools/s5/features.html#controlchart"&gt;various keys&lt;/a&gt; to navigate the presentation. If you just want to quickly scan through the content, you might find the outline view useful (press the &amp;#8220;T&amp;#8221; key to toggle between slideshow &amp;#38; outline modes).&lt;/p&gt;</description>
      <pubDate>Sun, 22 Jul 2007 20:48:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b30780d9-b0d5-4efb-9926-aac07f81c309</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/07/22/an-introduction-to-mock-objects-in-ruby</link>
      <category>mock</category>
      <category>object</category>
      <category>ruby</category>
      <category>mocha</category>
      <category>stub</category>
      <category>testing</category>
      <category>lrug</category>
    </item>
    <item>
      <title>Mocha 0.5 released</title>
      <description>&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  sudo gem install mocha&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;or &lt;a href="http://rubyforge.org/frs/?group_id=1917"&gt;download&lt;/a&gt; one of the latest packages from &lt;a href="http://rubyforge.org"&gt;rubyforge&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Parameter Matchers&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;ve added a few &lt;a href="http://code.google.com/p/hamcrest/wiki/Tutorial"&gt;Hamcrest-style&lt;/a&gt; parameter matchers which are designed to be used inside &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000021"&gt;&lt;code&gt;Expectation#with&lt;/code&gt;&lt;/a&gt;. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() &amp;#38; any_of(). More to follow soon. The idea is eventually to get rid of the nasty &lt;code&gt;parameter_block&lt;/code&gt; option on &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000021"&gt;&lt;code&gt;Expectation#with&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;has_key&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;key_1&lt;/span&gt;&lt;span class="punct"&gt;'))&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;key_1&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;key_2&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="comment"&gt;# no verification error raised&lt;/span&gt;

  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;has_key&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;key_1&lt;/span&gt;&lt;span class="punct"&gt;'))&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;key_2&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="comment"&gt;# verification error raised, because method was not called with Hash containing key: 'key_1'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Values Returned and Exceptions Raised on Consecutive Invocations&lt;/h3&gt;


	&lt;p&gt;Allow multiple calls to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000024"&gt;&lt;code&gt;Expectation#returns&lt;/code&gt;&lt;/a&gt; and &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000025"&gt;&lt;code&gt;Expectation#raises&lt;/code&gt;&lt;/a&gt; to build up a sequence of responses to invocations on the mock. Added syntactic sugar method &lt;code&gt;Expectation#then&lt;/code&gt; to allow more readable expectations.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;then&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;raises&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Exception&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;then&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;4&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 1&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 2&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; raises exception of class Exception&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Yields on Consecutive Invocations&lt;/h3&gt;


	&lt;p&gt;Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;yields&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;then&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;yields&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;3&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|*&lt;/span&gt;&lt;span class="ident"&gt;values&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;p&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; [1, 2]&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|*&lt;/span&gt;&lt;span class="ident"&gt;values&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;p&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; [3]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Multiple Yields on Single Invocation&lt;/h3&gt;


	&lt;p&gt;Added &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000023"&gt;&lt;code&gt;Expectation#multiple_yields&lt;/code&gt;&lt;/a&gt; to allow a mocked or stubbed method to yield multiple times for a single invocation.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;multiple_yields&lt;/span&gt;&lt;span class="punct"&gt;([&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;],&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="number"&gt;3&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|*&lt;/span&gt;&lt;span class="ident"&gt;values&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;p&lt;/span&gt; &lt;span class="ident"&gt;values&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; [1, 2] # =&amp;gt; [3]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Invocation Dispatch&lt;/h3&gt;


	&lt;p&gt;Expectations were already being matched in reverse order i.e. the most recently defined one was being found first. This is still the case, but we now stop matching an expectation when its maximum number of expected invocations is reached. c.f. &lt;a href="http://www.jmock.org/jmock1-dispatch.html"&gt;JMock v1&lt;/a&gt;. A stub will never stop matching by default. Hopefully this means we can soon get rid of the need to pass a &lt;code&gt;Proc&lt;/code&gt; to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000024"&gt;&lt;code&gt;Expectation#returns&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;object&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;()&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;2&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;expects&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:method&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;once&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 1&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 2&lt;/span&gt;
  &lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;method&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; 2&lt;/span&gt;
  &lt;span class="comment"&gt;# no verification error raised&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This should still work&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:now&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;parse&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;Mon Jan 01 00:00:00 UTC 2007&lt;/span&gt;&lt;span class="punct"&gt;'))&lt;/span&gt;
  &lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;now&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; Mon Jan 01 00:00:00 UTC 2007&lt;/span&gt;
  &lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;stubs&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:now&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;returns&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;parse&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;Thu Feb 01 00:00:00 UTC 2007&lt;/span&gt;&lt;span class="punct"&gt;'))&lt;/span&gt;
  &lt;span class="constant"&gt;Time&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;now&lt;/span&gt; &lt;span class="comment"&gt;# =&amp;gt; Thu Feb 01 00:00:00 UTC 2007&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Acknowledgements&lt;/h3&gt;


	&lt;p&gt;Thanks to David Chelimsky, Dan North, Jay Fields, Kevin Clark, Frederick Cheung, James Moore, Brian Helmkamp, Ben Griffiths, Chris Roos &amp;#38; Paul Battley for their input. Apologies to anybody I forgot to mention.&lt;/p&gt;</description>
      <pubDate>Fri, 08 Jun 2007 15:46:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:fa9f8740-ed2c-4f13-a1f6-3d2244dcb06f</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/06/08/mocha-0-5-released</link>
      <category>mocha_release</category>
      <category>mocha</category>
      <category>release</category>
      <category>mock</category>
      <category>stub</category>
      <category>testing</category>
      <category>ruby</category>
    </item>
    <item>
      <title>RSpec/Mocha compatibility</title>
      <description>&lt;p&gt;The &lt;a href="http://rspec.rubyforge.org/"&gt;RSpec&lt;/a&gt; team have just &lt;a href="http://www.nabble.com/forum/ViewPost.jtp?post=9843184"&gt;announced&lt;/a&gt; a beta version of their pending 0.9 release.&lt;/p&gt;


	&lt;p&gt;Apparently&amp;#8230;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;You can now use &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; by saying &lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;config&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;mock_with&lt;/span&gt; &lt;span class="symbol"&gt;:mocha&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; in a &lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;spec_helper&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Sounds good :-)&lt;/p&gt;</description>
      <pubDate>Wed, 04 Apr 2007 16:11:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:35f2f24f-a450-4a06-aa0e-754de3e55f0d</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/04/04/rspec-mocha-compatibility</link>
      <category>mocha</category>
      <category>rspec</category>
      <category>compatibility</category>
      <category>mock</category>
      <category>testing</category>
      <category>bdd</category>
    </item>
    <item>
      <title>Mocha 0.4 released</title>
      <description>&lt;p&gt;So I finally got round to releasing a &lt;a href="http://rubyforge.org/frs/?group_id=1917&amp;#38;release_id=9184"&gt;new version&lt;/a&gt; of &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt;. Much of the functionality has been available for some time if you&amp;#8217;ve been using the Rails plugin based on subversion &lt;span class="caps"&gt;HEAD&lt;/span&gt;, but now you can get it in all in a gem (or other package). The most recent changes centre around allowing mocking of Object instance methods.&lt;/p&gt;


	&lt;p&gt;Release notes&amp;#8230;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Allow naming of mocks (patch from &lt;a href="http://blog.seagul.co.uk"&gt;Chris Roos&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Specify multiple return values for consecutive calls.&lt;/li&gt;
		&lt;li&gt;Improved consistency of expectation error messages.&lt;/li&gt;
		&lt;li&gt;Allow mocking of Object instance methods e.g. kind_of?, type.&lt;/li&gt;
		&lt;li&gt;Provide aliased versions of #expects and #stubs to allow mocking of these methods.&lt;/li&gt;
		&lt;li&gt;Added at_least, at_most, at_most_once methods to expectation.&lt;/li&gt;
		&lt;li&gt;Allow expects and stubs to take a hash of method and return values.&lt;/li&gt;
		&lt;li&gt;Eliminate warning: &amp;#8220;instance variable @yield not initialized&amp;#8221; (patch from &lt;a href="http://blog.rhnh.net/"&gt;Xavier Shay&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Restore instance methods on partial mocks (patch from &lt;a href="http://blog.seagul.co.uk"&gt;Chris Roos&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Allow stubbing of a method with non-word chars in its name (patch from &lt;a href="http://po-ru.com"&gt;Paul Battley&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Removed coupling to &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Allow specified exception instance to be raised (patch from &lt;a href="http://blog.seagul.co.uk"&gt;Chris Roos&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Make mock object_id appear in hex like normal Ruby inspect (patch from &lt;a href="http://po-ru.com"&gt;Paul Battley&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Fix path to object.rb in rdoc rake task (patch from &lt;a href="http://www.workingwithrails.com/person/5103-tomas-pospisek"&gt;Tomas Pospisek&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Reverse order in which expectations are matched, so that last expectation is matched first. This allows e.g. a call to #stubs to be effectively overridden by a call to #expects (patch from &lt;a href="http://blog.leetsoft.com/"&gt;Tobias Lutke&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;Stubba &amp;#38; SmartTestCase modules incorporated into Mocha module so only need to require &amp;#8216;mocha&amp;#8217; &amp;#8211; no longer need to require &amp;#8216;stubba&amp;#8217;.&lt;/li&gt;
		&lt;li&gt;AutoMocha removed.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Thanks to all who contributed.&lt;/p&gt;


	&lt;p&gt;Enjoy :-)&lt;/p&gt;</description>
      <pubDate>Mon, 22 Jan 2007 12:28:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:21fc9eed-97c8-4ddf-9869-4c07cce42d46</guid>
      <author>James Mead</author>
      <link>http://blog.floehopper.org/articles/2007/01/22/mocha-0-4-released</link>
      <category>mocha_release</category>
      <category>mocha</category>
      <category>release</category>
      <category>mock</category>
      <category>stub</category>
      <category>testing</category>
      <category>rubyforge</category>
    </item>
  </channel>
</rss>
