<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.floehopper.org/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <title>Floehopper</title>
  <subtitle type="html">thoughts on the bergy bits of life</subtitle>
  <id>tag:blog.floehopper.org,2005:Typo</id>
  <generator uri="http://www.typosphere.org" version="4.0">Typo</generator>
  
  <link href="http://blog.floehopper.org/" rel="alternate" type="text/html" />
  <updated>2009-07-01T11:52:49+00:00</updated>
  <link rel="self" href="http://feeds.floehopper.org/floehopper-blog" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:aeaa3841-a0c4-401e-8b5c-185f9ae32d31</id>
    <published>2009-07-01T11:52:49+00:00</published>
    <updated>2009-07-01T11:52:49+00:00</updated>
    <title type="html">Mocha Release 0.9.7</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/eD6IKJOcslQ/mocha-release-0-9-7" rel="alternate" type="text/html" />
    <category term="mocha_release" scheme="http://blog.floehopper.org/articles/category/mocha_release" label="mocha_release" />
    <category term="mocha" scheme="http://blog.floehopper.org/articles/tag/mocha" />
    <category term="mock" scheme="http://blog.floehopper.org/articles/tag/mock" />
    <category term="stub" scheme="http://blog.floehopper.org/articles/tag/stub" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="testing" scheme="http://blog.floehopper.org/articles/tag/testing" />
    <category term="tdd" scheme="http://blog.floehopper.org/articles/tag/tdd" />
    <summary type="html">&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Although I had provided a deprecation warning for people using the now renamed &lt;a href="http://mocha.rubyforge.org/classes/Mocha/API.html"&gt;Mocha::Standalone&lt;/a&gt;, I had assumed people wouldn&amp;#8217;t be explicitly loading the &lt;code&gt;mocha/standalone.rb&lt;/code&gt; file. It turns out this assumption was incorrect at least in the case of &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;. This is now fixed.&lt;/li&gt;
	&lt;/ul&gt;</summary>
    <content type="html">&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Although I had provided a deprecation warning for people using the now renamed &lt;a href="http://mocha.rubyforge.org/classes/Mocha/API.html"&gt;Mocha::Standalone&lt;/a&gt;, I had assumed people wouldn&amp;#8217;t be explicitly loading the &lt;code&gt;mocha/standalone.rb&lt;/code&gt; file. It turns out this assumption was incorrect at least in the case of &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;. This is now fixed.&lt;/li&gt;
	&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/eD6IKJOcslQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/07/01/mocha-release-0-9-7</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:7ad172d1-6afc-4867-9f2d-8a5259c6509d</id>
    <published>2009-06-29T16:29:54+00:00</published>
    <updated>2009-06-29T16:29:54+00:00</updated>
    <title type="html">Mocha Release 0.9.6</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/uLyeGaqWxwQ/mocha-release-0-9-6" rel="alternate" type="text/html" />
    <category term="mocha_release" scheme="http://blog.floehopper.org/articles/category/mocha_release" label="mocha_release" />
    <category term="mocha" scheme="http://blog.floehopper.org/articles/tag/mocha" />
    <category term="mock" scheme="http://blog.floehopper.org/articles/tag/mock" />
    <category term="stub" scheme="http://blog.floehopper.org/articles/tag/stub" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="testing" scheme="http://blog.floehopper.org/articles/tag/testing" />
    <category term="tdd" scheme="http://blog.floehopper.org/articles/tag/tdd" />
    <summary type="html">&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Version 2.0.1 of the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; introduced a private &lt;code&gt;run_test&lt;/code&gt; method on &lt;code&gt;TestCase&lt;/code&gt; which clashed with the public &lt;code&gt;TestRunner#run_test&lt;/code&gt; method. So this latter method has been renamed to &lt;code&gt;run_as_test&lt;/code&gt;.&lt;/li&gt;
		&lt;li&gt;Stop requiring &lt;code&gt;rubygems&lt;/code&gt; &amp;#8211; this should be an environmental choice for the user. &lt;a href="http://gist.github.com/54177"&gt;This&lt;/a&gt; describes why requiring &lt;code&gt;rubygems&lt;/code&gt; in your library code is a bad idea.&lt;/li&gt;
		&lt;li&gt;It seems like overkill to vendorize &lt;code&gt;coderay&lt;/code&gt; and &lt;code&gt;meta_project&lt;/code&gt; when they&amp;#8217;re only needed to generate the examples for documentation and for publishing files on &lt;a href="http://rubyforge.org/"&gt;RubyForge&lt;/a&gt;. So I&amp;#8217;m removing them and installing them locally as gems when I need them.&lt;/li&gt;
		&lt;li&gt;Added support for &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; (version &amp;gt;= 2.0). Note that as with other versions of &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; I&amp;#8217;m completely replacing the &lt;code&gt;TestCase#run&lt;/code&gt; method. Unfortunately in version 2.0.0 this method differs slightly from the same method in version 2.0.1 &amp;#38; 2.0.2, so we have to provide different implementations to ensure that the internal working of &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; are not compromised by &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;. Note also that unless the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; is loaded, requiring &lt;code&gt;'test/unit'&lt;/code&gt; leads to a mixture of standard library and gem classes being loaded causing errors. To avoid a dependency on &lt;code&gt;rubygems&lt;/code&gt;, the gem is loaded only if &lt;code&gt;MOCHA_OPTIONS&lt;/code&gt; is set to &lt;code&gt;use_test_unit_gem&lt;/code&gt; &amp;#8211; this option is only intended for use in running &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&amp;#8217;s&lt;/a&gt; own tests. It might be worthwhile to create a shim gem like &lt;code&gt;minitest_tu_shim&lt;/code&gt; to allow the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; to completely replace the standard library, but that&amp;#8217;s a job for another day. &lt;a href="http://blog.floehopper.org/articles/2009/02/02/test-unit-and-minitest-with-different-ruby-versions#minitest-tu-shim"&gt;My previous article on Test::Unit and MiniTest&lt;/a&gt; explains how the &lt;code&gt;minitest-tu-shim&lt;/code&gt; works. The changes in the &lt;code&gt;Rakefile&lt;/code&gt; are to make the default task run with the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; (version &amp;gt;= 2.0).&lt;/li&gt;
		&lt;li&gt;Renamed &lt;code&gt;Mocha::Standalone&lt;/code&gt; to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/API.html"&gt;Mocha::API&lt;/a&gt; to better reflect its purpose. Added a deprecation warning for those who are referencing &lt;code&gt;Mocha::Standalone&lt;/code&gt;.&lt;/li&gt;
		&lt;li&gt;Fix exception raised by &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000015"&gt;HasEntry#matches?&lt;/a&gt; when first parameter is not a &lt;code&gt;Hash&lt;/code&gt; (thanks to &lt;a href="http://taylorbarstow.com/"&gt;Taylor Barstow&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.metaskills.net/"&gt;Ken Collins&lt;/a&gt; &lt;a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2060"&gt;reported&lt;/a&gt; that &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; is always loading &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if it is available and loading it causes some &lt;code&gt;Rails&lt;/code&gt;/&lt;code&gt;ActionPack&lt;/code&gt; tests to break. I&amp;#8217;ve removed the loading of &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, but this now means the user has to ensure that if they want to use &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; in conjunction with &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;, he must load &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; before loading &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Implemented &lt;a href="http://github.com/chneukirchen/bacon/"&gt;Bacon&lt;/a&gt; integration (thanks to &lt;a href="http://github.com/Bira"&gt;Ubiratan Pires Alberton&lt;/a&gt;), but this was then removed after deciding only to maintain integration with &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; and &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; which are both Ruby standard libraries. See &lt;a href="http://groups.google.com/group/mocha-developer/t/f01e55656e365567"&gt;mailing list message&lt;/a&gt; for details.&lt;/li&gt;
		&lt;li&gt;Don&amp;#8217;t monkey-patch &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if it&amp;#8217;s already been monkey-patched by &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/41"&gt;bug&lt;/a&gt; &amp;#8211; &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; integration was counting &lt;code&gt;ExpectationErrors&lt;/code&gt; as errors not failures.&lt;/li&gt;
		&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/43"&gt;bug&lt;/a&gt; &amp;#8211; Some &lt;a href="http://github.com/chneukirchen/bacon/"&gt;Bacon&lt;/a&gt; tests were failing in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://spicycode.com/"&gt;Chad Humphries&lt;/a&gt; pointed out that in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt;, if you are not using &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will attempt to load and monkey-patch &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;. &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will now only monkey-patch &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; and/or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if they have already been loaded. &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; tests will now run in both Ruby 1.8.6 (with &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; gem) and in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt; (with &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; standard library). See &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/49"&gt;Lighthouse ticket&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Made &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; compatible with minitest 1.4.0 and above (thanks to &lt;a href="http://stoneship.org/"&gt;Denis Defreyne&lt;/a&gt;).&lt;/li&gt;
	&lt;/ul&gt;</summary>
    <content type="html">&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Version 2.0.1 of the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; introduced a private &lt;code&gt;run_test&lt;/code&gt; method on &lt;code&gt;TestCase&lt;/code&gt; which clashed with the public &lt;code&gt;TestRunner#run_test&lt;/code&gt; method. So this latter method has been renamed to &lt;code&gt;run_as_test&lt;/code&gt;.&lt;/li&gt;
		&lt;li&gt;Stop requiring &lt;code&gt;rubygems&lt;/code&gt; &amp;#8211; this should be an environmental choice for the user. &lt;a href="http://gist.github.com/54177"&gt;This&lt;/a&gt; describes why requiring &lt;code&gt;rubygems&lt;/code&gt; in your library code is a bad idea.&lt;/li&gt;
		&lt;li&gt;It seems like overkill to vendorize &lt;code&gt;coderay&lt;/code&gt; and &lt;code&gt;meta_project&lt;/code&gt; when they&amp;#8217;re only needed to generate the examples for documentation and for publishing files on &lt;a href="http://rubyforge.org/"&gt;RubyForge&lt;/a&gt;. So I&amp;#8217;m removing them and installing them locally as gems when I need them.&lt;/li&gt;
		&lt;li&gt;Added support for &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; (version &amp;gt;= 2.0). Note that as with other versions of &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; I&amp;#8217;m completely replacing the &lt;code&gt;TestCase#run&lt;/code&gt; method. Unfortunately in version 2.0.0 this method differs slightly from the same method in version 2.0.1 &amp;#38; 2.0.2, so we have to provide different implementations to ensure that the internal working of &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; are not compromised by &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;. Note also that unless the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; is loaded, requiring &lt;code&gt;'test/unit'&lt;/code&gt; leads to a mixture of standard library and gem classes being loaded causing errors. To avoid a dependency on &lt;code&gt;rubygems&lt;/code&gt;, the gem is loaded only if &lt;code&gt;MOCHA_OPTIONS&lt;/code&gt; is set to &lt;code&gt;use_test_unit_gem&lt;/code&gt; &amp;#8211; this option is only intended for use in running &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&amp;#8217;s&lt;/a&gt; own tests. It might be worthwhile to create a shim gem like &lt;code&gt;minitest_tu_shim&lt;/code&gt; to allow the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; to completely replace the standard library, but that&amp;#8217;s a job for another day. &lt;a href="http://blog.floehopper.org/articles/2009/02/02/test-unit-and-minitest-with-different-ruby-versions#minitest-tu-shim"&gt;My previous article on Test::Unit and MiniTest&lt;/a&gt; explains how the &lt;code&gt;minitest-tu-shim&lt;/code&gt; works. The changes in the &lt;code&gt;Rakefile&lt;/code&gt; are to make the default task run with the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt; (version &amp;gt;= 2.0).&lt;/li&gt;
		&lt;li&gt;Renamed &lt;code&gt;Mocha::Standalone&lt;/code&gt; to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/API.html"&gt;Mocha::API&lt;/a&gt; to better reflect its purpose. Added a deprecation warning for those who are referencing &lt;code&gt;Mocha::Standalone&lt;/code&gt;.&lt;/li&gt;
		&lt;li&gt;Fix exception raised by &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000015"&gt;HasEntry#matches?&lt;/a&gt; when first parameter is not a &lt;code&gt;Hash&lt;/code&gt; (thanks to &lt;a href="http://taylorbarstow.com/"&gt;Taylor Barstow&lt;/a&gt;).&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.metaskills.net/"&gt;Ken Collins&lt;/a&gt; &lt;a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2060"&gt;reported&lt;/a&gt; that &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; is always loading &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if it is available and loading it causes some &lt;code&gt;Rails&lt;/code&gt;/&lt;code&gt;ActionPack&lt;/code&gt; tests to break. I&amp;#8217;ve removed the loading of &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, but this now means the user has to ensure that if they want to use &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; in conjunction with &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;, he must load &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; before loading &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Implemented &lt;a href="http://github.com/chneukirchen/bacon/"&gt;Bacon&lt;/a&gt; integration (thanks to &lt;a href="http://github.com/Bira"&gt;Ubiratan Pires Alberton&lt;/a&gt;), but this was then removed after deciding only to maintain integration with &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; and &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; which are both Ruby standard libraries. See &lt;a href="http://groups.google.com/group/mocha-developer/t/f01e55656e365567"&gt;mailing list message&lt;/a&gt; for details.&lt;/li&gt;
		&lt;li&gt;Don&amp;#8217;t monkey-patch &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if it&amp;#8217;s already been monkey-patched by &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/41"&gt;bug&lt;/a&gt; &amp;#8211; &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; integration was counting &lt;code&gt;ExpectationErrors&lt;/code&gt; as errors not failures.&lt;/li&gt;
		&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/43"&gt;bug&lt;/a&gt; &amp;#8211; Some &lt;a href="http://github.com/chneukirchen/bacon/"&gt;Bacon&lt;/a&gt; tests were failing in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://spicycode.com/"&gt;Chad Humphries&lt;/a&gt; pointed out that in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt;, if you are not using &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will attempt to load and monkey-patch &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;. &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will now only monkey-patch &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt; and/or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; if they have already been loaded. &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; tests will now run in both Ruby 1.8.6 (with &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; gem) and in &lt;a href="http://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/"&gt;Ruby 1.9.1&lt;/a&gt; (with &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt; standard library). See &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/49"&gt;Lighthouse ticket&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Made &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; compatible with minitest 1.4.0 and above (thanks to &lt;a href="http://stoneship.org/"&gt;Denis Defreyne&lt;/a&gt;).&lt;/li&gt;
	&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/uLyeGaqWxwQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/06/29/mocha-release-0-9-6</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:d89bf636-e29a-432e-a24e-634eb515c7e5</id>
    <published>2009-03-16T12:55:33+00:00</published>
    <updated>2009-03-16T12:59:27+00:00</updated>
    <title type="html">National Express East Coast Ticket Options</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/ZUyqTaE57Is/national-express-east-coast-ticket-options" rel="alternate" type="text/html" />
    <category term="durham" scheme="http://blog.floehopper.org/articles/tag/durham" />
    <category term="london" scheme="http://blog.floehopper.org/articles/tag/london" />
    <category term="national" scheme="http://blog.floehopper.org/articles/tag/national" />
    <category term="express" scheme="http://blog.floehopper.org/articles/tag/express" />
    <category term="east" scheme="http://blog.floehopper.org/articles/tag/east" />
    <category term="coast" scheme="http://blog.floehopper.org/articles/tag/coast" />
    <category term="train" scheme="http://blog.floehopper.org/articles/tag/train" />
    <category term="ticket" scheme="http://blog.floehopper.org/articles/tag/ticket" />
    <category term="fare" scheme="http://blog.floehopper.org/articles/tag/fare" />
    <category term="nxec" scheme="http://blog.floehopper.org/articles/tag/nxec" />
    <category term="super" scheme="http://blog.floehopper.org/articles/tag/super" />
    <category term="off" scheme="http://blog.floehopper.org/articles/tag/off" />
    <category term="peak" scheme="http://blog.floehopper.org/articles/tag/peak" />
    <category term="anytime" scheme="http://blog.floehopper.org/articles/tag/anytime" />
    <category term="return" scheme="http://blog.floehopper.org/articles/tag/return" />
    <summary type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In the past, I&amp;#8217;ve tended &lt;a href="http://blog.floehopper.org/articles/2007/01/12/finding-the-cheapest-train-fare"&gt;to buy Advance Single tickets&lt;/a&gt; for most of my journeys between Durham and London. This is usually the best option when booking a couple of months ahead, but when you have to book at shorter notice, I often overlook some of the return fares.&lt;/p&gt;


	&lt;p&gt;Despite the supposed &lt;a href="http://www.guardian.co.uk/money/2008/may/24/consumeraffairs.railtravel"&gt;simplification of UK train fares&lt;/a&gt;, it&amp;#8217;s not straightforward to find all the relevant information in one place, so I thought I&amp;#8217;d write it up here. I hope other people might find this useful, but please double-check with the &lt;a href="http://www.nationalexpresseastcoast.com/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; website&lt;/a&gt; or a Travel Centre before spending any money.&lt;/p&gt;


	&lt;h3&gt;Fares from Durham to London&lt;/h3&gt;


	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;Ticket Type&lt;/td&gt;
			&lt;td&gt;Cost&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Super Off-Peak Return&lt;/td&gt;
			&lt;td&gt;105.00&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Off-Peak Return&lt;/td&gt;
			&lt;td&gt;163.80&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Business Carnet&lt;/td&gt;
			&lt;td&gt;239.40&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Anytime Return&lt;/td&gt;
			&lt;td&gt;266.00&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;First Class Anytime Return&lt;/td&gt;
			&lt;td&gt;370.00&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




	&lt;h3&gt;Super Off-Peak Return Conditions&lt;/h3&gt;


	&lt;h4&gt;Northbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train from London King&amp;#8217;s Cross except those timed to depart before 0929 Monday-Friday and from 1457-1859 inclusive, Monday-Thursday and from 1457-1815 on Fridays.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the following &lt;em&gt;direct&lt;/em&gt; services, departing London: 0930, 1130, 1230 &amp;#38; 1430, 1830&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 1900, 1930&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 2000, 2100.&lt;/p&gt;


	&lt;h4&gt;Southbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train timed to arrive in London King&amp;#8217;s Cross 1117 or later, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the 0845 departure from Durham or any later train.&lt;/p&gt;


	&lt;h3&gt;Off-Peak Return Conditions&lt;/h3&gt;


	&lt;h4&gt;Northbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train from London King&amp;#8217;s Cross except those timed to depart 0645-0815 inclusive, Monday-Friday. Outward portions also barred 1559-1745 inclusive, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the following &lt;em&gt;direct&lt;/em&gt; services, departing London: 0615, 0830, 0930, 1130, 1230 &amp;#38; 1430, 1530, 1820, 1830, 1900, 1930&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 2000, 2100.&lt;/p&gt;


	&lt;h4&gt;Southbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train timed to arrive in London King&amp;#8217;s Cross 1020 or later, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the 0804 departure from Durham or any later train.&lt;/p&gt;


	&lt;h3&gt;Business Carnet&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;10 Anytime Return tickets for the price of 9.&lt;/li&gt;
		&lt;li&gt;To be used within a 3 month period.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;References&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.nationalexpresseastcoast.com/Travel-Information/Ticket-Options1/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; Ticket Options&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.nationalexpresseastcoast.com/Travel-Information/General-ticket-information/Ticket-Sales-Terms-and-Conditions/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; Ticket Sales Terms and Conditions&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Fridays only&lt;/p&gt;</summary>
    <content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In the past, I&amp;#8217;ve tended &lt;a href="http://blog.floehopper.org/articles/2007/01/12/finding-the-cheapest-train-fare"&gt;to buy Advance Single tickets&lt;/a&gt; for most of my journeys between Durham and London. This is usually the best option when booking a couple of months ahead, but when you have to book at shorter notice, I often overlook some of the return fares.&lt;/p&gt;


	&lt;p&gt;Despite the supposed &lt;a href="http://www.guardian.co.uk/money/2008/may/24/consumeraffairs.railtravel"&gt;simplification of UK train fares&lt;/a&gt;, it&amp;#8217;s not straightforward to find all the relevant information in one place, so I thought I&amp;#8217;d write it up here. I hope other people might find this useful, but please double-check with the &lt;a href="http://www.nationalexpresseastcoast.com/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; website&lt;/a&gt; or a Travel Centre before spending any money.&lt;/p&gt;


	&lt;h3&gt;Fares from Durham to London&lt;/h3&gt;


	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;Ticket Type&lt;/td&gt;
			&lt;td&gt;Cost&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Super Off-Peak Return&lt;/td&gt;
			&lt;td&gt;105.00&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Off-Peak Return&lt;/td&gt;
			&lt;td&gt;163.80&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Business Carnet&lt;/td&gt;
			&lt;td&gt;239.40&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Anytime Return&lt;/td&gt;
			&lt;td&gt;266.00&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;First Class Anytime Return&lt;/td&gt;
			&lt;td&gt;370.00&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




	&lt;h3&gt;Super Off-Peak Return Conditions&lt;/h3&gt;


	&lt;h4&gt;Northbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train from London King&amp;#8217;s Cross except those timed to depart before 0929 Monday-Friday and from 1457-1859 inclusive, Monday-Thursday and from 1457-1815 on Fridays.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the following &lt;em&gt;direct&lt;/em&gt; services, departing London: 0930, 1130, 1230 &amp;#38; 1430, 1830&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 1900, 1930&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 2000, 2100.&lt;/p&gt;


	&lt;h4&gt;Southbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train timed to arrive in London King&amp;#8217;s Cross 1117 or later, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the 0845 departure from Durham or any later train.&lt;/p&gt;


	&lt;h3&gt;Off-Peak Return Conditions&lt;/h3&gt;


	&lt;h4&gt;Northbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train from London King&amp;#8217;s Cross except those timed to depart 0645-0815 inclusive, Monday-Friday. Outward portions also barred 1559-1745 inclusive, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the following &lt;em&gt;direct&lt;/em&gt; services, departing London: 0615, 0830, 0930, 1130, 1230 &amp;#38; 1430, 1530, 1820, 1830, 1900, 1930&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;, 2000, 2100.&lt;/p&gt;


	&lt;h4&gt;Southbound&lt;/h4&gt;


	&lt;p&gt;Valid on any train timed to arrive in London King&amp;#8217;s Cross 1020 or later, Monday-Friday.&lt;/p&gt;


	&lt;p&gt;On a weekday, this means you can travel on the 0804 departure from Durham or any later train.&lt;/p&gt;


	&lt;h3&gt;Business Carnet&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;10 Anytime Return tickets for the price of 9.&lt;/li&gt;
		&lt;li&gt;To be used within a 3 month period.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;References&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.nationalexpresseastcoast.com/Travel-Information/Ticket-Options1/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; Ticket Options&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.nationalexpresseastcoast.com/Travel-Information/General-ticket-information/Ticket-Sales-Terms-and-Conditions/"&gt;&lt;span class="caps"&gt;NXEC&lt;/span&gt; Ticket Sales Terms and Conditions&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Fridays only&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/ZUyqTaE57Is" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/03/16/national-express-east-coast-ticket-options</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:a1307b14-14dc-49c0-ab06-d8212a29d2a9</id>
    <published>2009-03-08T11:06:53+00:00</published>
    <updated>2009-03-09T16:07:42+00:00</updated>
    <title type="html">National Hack the Government Day</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/BfEUmaA6eVs/national-hack-the-government-day" rel="alternate" type="text/html" />
    <category term="hack" scheme="http://blog.floehopper.org/articles/tag/hack" />
    <category term="uk" scheme="http://blog.floehopper.org/articles/tag/uk" />
    <category term="government" scheme="http://blog.floehopper.org/articles/tag/government" />
    <category term="rewiredstate" scheme="http://blog.floehopper.org/articles/tag/rewiredstate" />
    <category term="guardian" scheme="http://blog.floehopper.org/articles/tag/guardian" />
    <category term="greasemonkey" scheme="http://blog.floehopper.org/articles/tag/greasemonkey" />
    <category term="jquery" scheme="http://blog.floehopper.org/articles/tag/jquery" />
    <summary type="html">&lt;p&gt;I spent yesterday in the &lt;a href="http://www.guardian.co.uk/media/gallery/2008/dec/15/theguardian-pressandpublishing"&gt;shiny new Guardian offices&lt;/a&gt; at &lt;a href="http://rewiredstate.org/"&gt;Rewired State&lt;/a&gt; &amp;#8211; National Hack the Government Day &amp;#8211; which was a lot of fun, despite the &lt;a href="http://twitter.com/floehopper/status/1291802649"&gt;early start&lt;/a&gt;. There was a really friendly atmosphere and lots of interesting &lt;a href="http://projects.rewiredstate.org/"&gt;projects&lt;/a&gt; going on.&lt;/p&gt;


	&lt;h3&gt;&lt;span class="caps"&gt;ONS&lt;/span&gt; Graphs&lt;/h3&gt;


	&lt;p&gt;I teamed up with &lt;a href="http://po-ru.com/"&gt;Paul&lt;/a&gt; to work on some improvements for the &lt;a href="http://www.statistics.gov.uk/"&gt;Office for National Statistics website&lt;/a&gt;. We&amp;#8217;d noticed that while there are many &lt;a href="http://www.statistics.gov.uk/statbase/tsdtimezone.asp"&gt;timeline datasets&lt;/a&gt; available on the site, the only way to view graphs of the data is to download a Windows application called &lt;a href="http://www.statistics.gov.uk/statbase/Navidata.asp"&gt;Navidata&lt;/a&gt;. Although it&amp;#8217;s free, this application is pretty clunky and hard to use and doesn&amp;#8217;t generate very clear graphs. Also, rather obviously, it isn&amp;#8217;t much use to Mac or Linux users.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; More about our hack from Paul &amp;#8211; &lt;a href="http://po-ru.com/diary/greasemonkey-vs-the-ons-at-rewired-state/"&gt;GreaseMonkey vs the &lt;span class="caps"&gt;ONS&lt;/span&gt; at Rewired State&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;So for the first part of our hack, in a fine example of &lt;a href="http://www.postmodernprogramming.org/"&gt;post-modern programming&lt;/a&gt;, we decided to use JavaScript to generate a graph in the browser using the &lt;span class="caps"&gt;HTML&lt;/span&gt; table form of the data. Thanks to an &lt;a href="http://blog.rebeccamurphey.com/2007/12/17/graph-table-data-jquery-flot/"&gt;article by Rebecca Murphey&lt;/a&gt;, we decided to use &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; together with Rebecca&amp;#8217;s &lt;a href="http://plugins.jquery.com/files/jquery.graphTable-0.2.js.txt"&gt;graphTable&lt;/a&gt; jQuery plugin which uses the &lt;a href="http://code.google.com/p/flot/"&gt;flot&lt;/a&gt; jQuery plugin to actually draw the graphs. We used the &lt;a href="https://addons.mozilla.org/firefox/addon/748"&gt;GreaseMonkey&lt;/a&gt;, the Firefox add-on, to write a &lt;a href="http://github.com/threedaymonk/ons_graphs/"&gt;little script&lt;/a&gt; to pull everything together.&lt;/p&gt;


&lt;div class='broken_flickr_link'&gt;`3335553400' could not be displayed because: &lt;br /&gt;File does not exist: .&lt;/div&gt;

	&lt;p&gt;So now anyone can use this script to view graphs of &lt;span class="caps"&gt;ONS&lt;/span&gt; timeline datasets :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Get &lt;a href="http://getfirefox.com/"&gt;Firefox&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Install &lt;a href="https://addons.mozilla.org/firefox/addon/748"&gt;GreaseMonkey&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Install &lt;a href="http://github.com/threedaymonk/ons_graphs/raw/3ff8362c76e3dc82e94857cd255d244af1174f78/ons_graphs.user.js"&gt;ons_graphs.user.js&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Browse to a &lt;a href="http://www.statistics.gov.uk/statbase/tsdtimezone.asp"&gt;timeline dataset&lt;/a&gt;, View Table, View Series, Add to Selection, Download then View On-Screen.&lt;/li&gt;
	&lt;/ul&gt;


&lt;div class='broken_flickr_link'&gt;`3336023889' could not be displayed because: &lt;br /&gt;File does not exist: .&lt;/div&gt;

	&lt;h3&gt;&lt;span class="caps"&gt;ONS&lt;/span&gt; Navigation&lt;/h3&gt;


	&lt;p&gt;For the second part of our hack, we wanted to make a better way of navigating to the datasets. The current system uses a series of forms in a &lt;a href="http://is.gd/mnk1"&gt;wizard-like&lt;/a&gt; experience which is quite hard to understand. Also, because of the form submissions (i.e. &lt;span class="caps"&gt;HTTP&lt;/span&gt; POSTs) required to access the datasets, there are no permanent URLs available to navigate directly to a dataset. We decided to try to remedy this by using &lt;a href="http://mechanize.rubyforge.org/mechanize/"&gt;Mechanize&lt;/a&gt; to scrape the timeline data from the website and then build a simplified static website using only links (i.e. &lt;span class="caps"&gt;HTTP&lt;/span&gt; GETs). However, we hit a snag in automatically submitting the last form in the wizard and ran out of time. I might try and have a go at this in the future if I get time.&lt;/p&gt;


	&lt;p&gt;We did notice that this last form had a hidden field containing what appeared to by a &lt;span class="caps"&gt;SQL&lt;/span&gt; query, making it ripe for &lt;a href="http://en.wikipedia.org/wiki/SQL_injection"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; injection attack&lt;/a&gt;, but fortunately we managed to restrain ourselves.&lt;/p&gt;


	&lt;p&gt;Thanks to &lt;a href="http://bendodson.com/"&gt;Ben Dodson&lt;/a&gt; &amp;#38; &lt;a href="http://po-ru.com/"&gt;Paul Battley&lt;/a&gt; for the photos.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I spent yesterday in the &lt;a href="http://www.guardian.co.uk/media/gallery/2008/dec/15/theguardian-pressandpublishing"&gt;shiny new Guardian offices&lt;/a&gt; at &lt;a href="http://rewiredstate.org/"&gt;Rewired State&lt;/a&gt; &amp;#8211; National Hack the Government Day &amp;#8211; which was a lot of fun, despite the &lt;a href="http://twitter.com/floehopper/status/1291802649"&gt;early start&lt;/a&gt;. There was a really friendly atmosphere and lots of interesting &lt;a href="http://projects.rewiredstate.org/"&gt;projects&lt;/a&gt; going on.&lt;/p&gt;


	&lt;h3&gt;&lt;span class="caps"&gt;ONS&lt;/span&gt; Graphs&lt;/h3&gt;


	&lt;p&gt;I teamed up with &lt;a href="http://po-ru.com/"&gt;Paul&lt;/a&gt; to work on some improvements for the &lt;a href="http://www.statistics.gov.uk/"&gt;Office for National Statistics website&lt;/a&gt;. We&amp;#8217;d noticed that while there are many &lt;a href="http://www.statistics.gov.uk/statbase/tsdtimezone.asp"&gt;timeline datasets&lt;/a&gt; available on the site, the only way to view graphs of the data is to download a Windows application called &lt;a href="http://www.statistics.gov.uk/statbase/Navidata.asp"&gt;Navidata&lt;/a&gt;. Although it&amp;#8217;s free, this application is pretty clunky and hard to use and doesn&amp;#8217;t generate very clear graphs. Also, rather obviously, it isn&amp;#8217;t much use to Mac or Linux users.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; More about our hack from Paul &amp;#8211; &lt;a href="http://po-ru.com/diary/greasemonkey-vs-the-ons-at-rewired-state/"&gt;GreaseMonkey vs the &lt;span class="caps"&gt;ONS&lt;/span&gt; at Rewired State&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;So for the first part of our hack, in a fine example of &lt;a href="http://www.postmodernprogramming.org/"&gt;post-modern programming&lt;/a&gt;, we decided to use JavaScript to generate a graph in the browser using the &lt;span class="caps"&gt;HTML&lt;/span&gt; table form of the data. Thanks to an &lt;a href="http://blog.rebeccamurphey.com/2007/12/17/graph-table-data-jquery-flot/"&gt;article by Rebecca Murphey&lt;/a&gt;, we decided to use &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; together with Rebecca&amp;#8217;s &lt;a href="http://plugins.jquery.com/files/jquery.graphTable-0.2.js.txt"&gt;graphTable&lt;/a&gt; jQuery plugin which uses the &lt;a href="http://code.google.com/p/flot/"&gt;flot&lt;/a&gt; jQuery plugin to actually draw the graphs. We used the &lt;a href="https://addons.mozilla.org/firefox/addon/748"&gt;GreaseMonkey&lt;/a&gt;, the Firefox add-on, to write a &lt;a href="http://github.com/threedaymonk/ons_graphs/"&gt;little script&lt;/a&gt; to pull everything together.&lt;/p&gt;


&lt;div class='broken_flickr_link'&gt;`3335553400' could not be displayed because: &lt;br /&gt;File does not exist: .&lt;/div&gt;

	&lt;p&gt;So now anyone can use this script to view graphs of &lt;span class="caps"&gt;ONS&lt;/span&gt; timeline datasets :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Get &lt;a href="http://getfirefox.com/"&gt;Firefox&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Install &lt;a href="https://addons.mozilla.org/firefox/addon/748"&gt;GreaseMonkey&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Install &lt;a href="http://github.com/threedaymonk/ons_graphs/raw/3ff8362c76e3dc82e94857cd255d244af1174f78/ons_graphs.user.js"&gt;ons_graphs.user.js&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Browse to a &lt;a href="http://www.statistics.gov.uk/statbase/tsdtimezone.asp"&gt;timeline dataset&lt;/a&gt;, View Table, View Series, Add to Selection, Download then View On-Screen.&lt;/li&gt;
	&lt;/ul&gt;


&lt;div class='broken_flickr_link'&gt;`3336023889' could not be displayed because: &lt;br /&gt;File does not exist: .&lt;/div&gt;

	&lt;h3&gt;&lt;span class="caps"&gt;ONS&lt;/span&gt; Navigation&lt;/h3&gt;


	&lt;p&gt;For the second part of our hack, we wanted to make a better way of navigating to the datasets. The current system uses a series of forms in a &lt;a href="http://is.gd/mnk1"&gt;wizard-like&lt;/a&gt; experience which is quite hard to understand. Also, because of the form submissions (i.e. &lt;span class="caps"&gt;HTTP&lt;/span&gt; POSTs) required to access the datasets, there are no permanent URLs available to navigate directly to a dataset. We decided to try to remedy this by using &lt;a href="http://mechanize.rubyforge.org/mechanize/"&gt;Mechanize&lt;/a&gt; to scrape the timeline data from the website and then build a simplified static website using only links (i.e. &lt;span class="caps"&gt;HTTP&lt;/span&gt; GETs). However, we hit a snag in automatically submitting the last form in the wizard and ran out of time. I might try and have a go at this in the future if I get time.&lt;/p&gt;


	&lt;p&gt;We did notice that this last form had a hidden field containing what appeared to by a &lt;span class="caps"&gt;SQL&lt;/span&gt; query, making it ripe for &lt;a href="http://en.wikipedia.org/wiki/SQL_injection"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt; injection attack&lt;/a&gt;, but fortunately we managed to restrain ourselves.&lt;/p&gt;


	&lt;p&gt;Thanks to &lt;a href="http://bendodson.com/"&gt;Ben Dodson&lt;/a&gt; &amp;#38; &lt;a href="http://po-ru.com/"&gt;Paul Battley&lt;/a&gt; for the photos.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/BfEUmaA6eVs" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/03/08/national-hack-the-government-day</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:99d2c410-ff54-4643-9865-47c83bea10fb</id>
    <published>2009-02-16T15:56:48+00:00</published>
    <updated>2009-03-17T13:17:34+00:00</updated>
    <title type="html">Uninstalling gems from .gem directory</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/JlpPbhHDabY/uninstalling-gems-from-gem-directory" rel="alternate" type="text/html" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="gem" scheme="http://blog.floehopper.org/articles/tag/gem" />
    <category term="uninstall" scheme="http://blog.floehopper.org/articles/tag/uninstall" />
    <category term="user" scheme="http://blog.floehopper.org/articles/tag/user" />
    <category term="home" scheme="http://blog.floehopper.org/articles/tag/home" />
    <category term="directory" scheme="http://blog.floehopper.org/articles/tag/directory" />
    <category term="sudo" scheme="http://blog.floehopper.org/articles/tag/sudo" />
    <category term="superuser" scheme="http://blog.floehopper.org/articles/tag/superuser" />
    <category term="osx" scheme="http://blog.floehopper.org/articles/tag/osx" />
    <summary type="html">&lt;p&gt;I keep forgetting how to do this, so I thought I&amp;#8217;d write myself some notes.&lt;/p&gt;


	&lt;p&gt;In a recent version, &lt;a href="http://www.rubygems.org/"&gt;RubyGems&lt;/a&gt; changed it&amp;#8217;s behaviour on &lt;code&gt;gem install&lt;/code&gt; so that if it doesn&amp;#8217;t have sufficient permission to install the gem files, it installs them in &lt;code&gt;~/.gem&lt;/code&gt; and generates a warning :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem install &amp;lt;gem-name&amp;gt;
  WARNING:  Installing to ~/.gem since /usr/local/ruby-1.8.6-p287/lib/ruby/gems/1.8 and
    /usr/local/ruby-1.8.6-p287/bin aren't both writable.
  WARNING:  You don't have /Users/jamesmead/.gem/ruby/1.8/bin in your PATH,
    gem executables will not run.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Sometimes (e.g. when you forgot to prepend &lt;a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/sudo.8.html"&gt;&lt;code&gt;sudo&lt;/code&gt;&lt;/a&gt;) this isn&amp;#8217;t what you want. However, it&amp;#8217;s not obvious how to uninstall the gem again to correct your mistake :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem uninstall &amp;lt;gem-name&amp;gt;
  ERROR:  While executing gem ... (Gem::InstallError)
    Unknown gem &amp;lt;gem-name&amp;gt; &amp;gt;= 0&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;To make this work, you need to specify the &lt;code&gt;install-dir&lt;/code&gt; option :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem uninstall &amp;lt;gem-name&amp;gt; --install-dir=~/.gem/ruby/1.8/
  Successfully uninstalled &amp;lt;gem-name&amp;gt;-x.y.z&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Note that if you are using Ruby 1.9, it looks like the RubyGems directory path includes the point release version number e.g. &lt;code&gt;1.9.0&lt;/code&gt; or &lt;code&gt;1.9.1&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Prevention is better than cure. Coderr suggests &lt;a href="http://coderrr.wordpress.com/2009/03/16/protecting-your-gem-directory/"&gt;protecting your ~/.gem directory&lt;/a&gt;.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I keep forgetting how to do this, so I thought I&amp;#8217;d write myself some notes.&lt;/p&gt;


	&lt;p&gt;In a recent version, &lt;a href="http://www.rubygems.org/"&gt;RubyGems&lt;/a&gt; changed it&amp;#8217;s behaviour on &lt;code&gt;gem install&lt;/code&gt; so that if it doesn&amp;#8217;t have sufficient permission to install the gem files, it installs them in &lt;code&gt;~/.gem&lt;/code&gt; and generates a warning :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem install &amp;lt;gem-name&amp;gt;
  WARNING:  Installing to ~/.gem since /usr/local/ruby-1.8.6-p287/lib/ruby/gems/1.8 and
    /usr/local/ruby-1.8.6-p287/bin aren't both writable.
  WARNING:  You don't have /Users/jamesmead/.gem/ruby/1.8/bin in your PATH,
    gem executables will not run.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Sometimes (e.g. when you forgot to prepend &lt;a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/sudo.8.html"&gt;&lt;code&gt;sudo&lt;/code&gt;&lt;/a&gt;) this isn&amp;#8217;t what you want. However, it&amp;#8217;s not obvious how to uninstall the gem again to correct your mistake :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem uninstall &amp;lt;gem-name&amp;gt;
  ERROR:  While executing gem ... (Gem::InstallError)
    Unknown gem &amp;lt;gem-name&amp;gt; &amp;gt;= 0&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;To make this work, you need to specify the &lt;code&gt;install-dir&lt;/code&gt; option :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;  $ gem uninstall &amp;lt;gem-name&amp;gt; --install-dir=~/.gem/ruby/1.8/
  Successfully uninstalled &amp;lt;gem-name&amp;gt;-x.y.z&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Note that if you are using Ruby 1.9, it looks like the RubyGems directory path includes the point release version number e.g. &lt;code&gt;1.9.0&lt;/code&gt; or &lt;code&gt;1.9.1&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Prevention is better than cure. Coderr suggests &lt;a href="http://coderrr.wordpress.com/2009/03/16/protecting-your-gem-directory/"&gt;protecting your ~/.gem directory&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/JlpPbhHDabY" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/02/16/uninstalling-gems-from-gem-directory</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:f8a30b4f-5516-4fb1-ac63-dd68dc3ae619</id>
    <published>2009-02-09T11:40:00+00:00</published>
    <updated>2009-02-09T11:57:26+00:00</updated>
    <title type="html">Mocha Configuration</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/BI9gvroSqI8/mocha-configuration" rel="alternate" type="text/html" />
    <category term="mocha" scheme="http://blog.floehopper.org/articles/tag/mocha" />
    <category term="mock" scheme="http://blog.floehopper.org/articles/tag/mock" />
    <category term="stub" scheme="http://blog.floehopper.org/articles/tag/stub" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="testing" scheme="http://blog.floehopper.org/articles/tag/testing" />
    <category term="tdd" scheme="http://blog.floehopper.org/articles/tag/tdd" />
    <category term="configuration" scheme="http://blog.floehopper.org/articles/tag/configuration" />
    <category term="warning" scheme="http://blog.floehopper.org/articles/tag/warning" />
    <category term="role" scheme="http://blog.floehopper.org/articles/tag/role" />
    <category term="interface" scheme="http://blog.floehopper.org/articles/tag/interface" />
    <category term="coupling" scheme="http://blog.floehopper.org/articles/tag/coupling" />
    <summary type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In his &lt;a href="http://blog.brianguthrie.com/articles/2009/02/03/ioke-mocking-mocha-as-exemplar"&gt;recent look&lt;/a&gt; at Mocha&amp;#8217;s internals, Brian Guthrie mentioned that he hadn&amp;#8217;t realised it was possible to configure Mocha to warn or disallow mocking of non-existent methods. So I thought it was time I explained &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Configuration.html"&gt;Mocha&amp;#8217;s configuration settings&lt;/a&gt;. These configuration settings are all somewhat experimental and feedback on their effectiveness would be welcome.&lt;/p&gt;


	&lt;p&gt;There are 3 levels for all of the existing conditions :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# default behaviour&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;allow&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="comment"&gt;# warning is displayed when condition is met&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;warn_when&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="comment"&gt;# error is raised when condition is met&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Stubbing a non-existent method&lt;/h3&gt;


	&lt;p&gt;This is useful if you want to ensure that methods you&amp;#8217;re mocking really exist. A common criticism of unit tests with mock objects is that such a test may (incorrectly) pass when an equivalent non-mocking test would (correctly) fail. While you should always have some integration tests, particularly for critical business functionality, this Mocha configuration setting should catch scenarios when mocked methods and real methods have become misaligned.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_non_existent_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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_that_doesnt_exist&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing non-existent method:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593760&amp;gt;.method_that_doesnt_exist&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;h3&gt;Stubbing a method unnecessarily&lt;/h3&gt;


	&lt;p&gt;This is useful for identifying unused stubs. Unused stubs are often accidentally introduced when code is &lt;a href="http://martinfowler.com/bliki/DefinitionOfRefactoring.html"&gt;refactored&lt;/a&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_method_unnecessarily&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&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;example&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;example&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;:unused_stub&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing method unnecessarily:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Mock:example&amp;gt;.unused_stub(any_parameters)&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;h3&gt;Stubbing a non-public method&lt;/h3&gt;


	&lt;p&gt;Many people think that it&amp;#8217;s good practice only to mock public methods. This is one way to prevent your tests being too tightly coupled to the internal implementation of a class. Such tests tend to be very brittle and not much use when refactoring.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_non_public_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;internal_method&lt;/span&gt;&lt;span class="punct"&gt;;&lt;/span&gt; &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="ident"&gt;private&lt;/span&gt; &lt;span class="symbol"&gt;:internal_method&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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;:internal_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing non-public method:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593530&amp;gt;.internal_method&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;h3&gt;Stubbing Method on Non-Mock Object&lt;/h3&gt;


	&lt;p&gt;If you like the idea of &lt;a href="http://www.jmock.org/oopsla2004.pdf"&gt;mocking roles not objects&lt;/a&gt; and &lt;a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html"&gt;you don&amp;#8217;t like stubbing concrete classes&lt;/a&gt;, this is the setting for you. However, while this restriction makes a lot of sense in Java with its &lt;a href="http://java.sun.com/docs/books/tutorial/java/concepts/interface.html"&gt;explicit interfaces&lt;/a&gt;, it may be moot in Ruby where roles are probably best represented as Modules. Anyway that&amp;#8217;s probably a discussion for another day.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_method_on_non_mock_object&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;example_method&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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;:example_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing method on non-mock object:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593620&amp;gt;.example_method&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;</summary>
    <content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In his &lt;a href="http://blog.brianguthrie.com/articles/2009/02/03/ioke-mocking-mocha-as-exemplar"&gt;recent look&lt;/a&gt; at Mocha&amp;#8217;s internals, Brian Guthrie mentioned that he hadn&amp;#8217;t realised it was possible to configure Mocha to warn or disallow mocking of non-existent methods. So I thought it was time I explained &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Configuration.html"&gt;Mocha&amp;#8217;s configuration settings&lt;/a&gt;. These configuration settings are all somewhat experimental and feedback on their effectiveness would be welcome.&lt;/p&gt;


	&lt;p&gt;There are 3 levels for all of the existing conditions :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# default behaviour&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;allow&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="comment"&gt;# warning is displayed when condition is met&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;warn_when&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="comment"&gt;# error is raised when condition is met&lt;/span&gt;
  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;condition&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Stubbing a non-existent method&lt;/h3&gt;


	&lt;p&gt;This is useful if you want to ensure that methods you&amp;#8217;re mocking really exist. A common criticism of unit tests with mock objects is that such a test may (incorrectly) pass when an equivalent non-mocking test would (correctly) fail. While you should always have some integration tests, particularly for critical business functionality, this Mocha configuration setting should catch scenarios when mocked methods and real methods have become misaligned.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_non_existent_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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_that_doesnt_exist&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing non-existent method:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593760&amp;gt;.method_that_doesnt_exist&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;h3&gt;Stubbing a method unnecessarily&lt;/h3&gt;


	&lt;p&gt;This is useful for identifying unused stubs. Unused stubs are often accidentally introduced when code is &lt;a href="http://martinfowler.com/bliki/DefinitionOfRefactoring.html"&gt;refactored&lt;/a&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_method_unnecessarily&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&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;example&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
      &lt;span class="ident"&gt;example&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;:unused_stub&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing method unnecessarily:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Mock:example&amp;gt;.unused_stub(any_parameters)&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;h3&gt;Stubbing a non-public method&lt;/h3&gt;


	&lt;p&gt;Many people think that it&amp;#8217;s good practice only to mock public methods. This is one way to prevent your tests being too tightly coupled to the internal implementation of a class. Such tests tend to be very brittle and not much use when refactoring.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_non_public_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;internal_method&lt;/span&gt;&lt;span class="punct"&gt;;&lt;/span&gt; &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="ident"&gt;private&lt;/span&gt; &lt;span class="symbol"&gt;:internal_method&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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;:internal_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing non-public method:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593530&amp;gt;.internal_method&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;h3&gt;Stubbing Method on Non-Mock Object&lt;/h3&gt;


	&lt;p&gt;If you like the idea of &lt;a href="http://www.jmock.org/oopsla2004.pdf"&gt;mocking roles not objects&lt;/a&gt; and &lt;a href="http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html"&gt;you don&amp;#8217;t like stubbing concrete classes&lt;/a&gt;, this is the setting for you. However, while this restriction makes a lot of sense in Java with its &lt;a href="http://java.sun.com/docs/books/tutorial/java/concepts/interface.html"&gt;explicit interfaces&lt;/a&gt;, it may be moot in Ruby where roles are probably best represented as Modules. Anyway that&amp;#8217;s probably a discussion for another day.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="constant"&gt;Mocha&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;prevent&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:stubbing_method_on_non_mock_object&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Example&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;example_method&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;ExampleTest&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_example&lt;/span&gt;
      &lt;span class="ident"&gt;example&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Example&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;example&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;:example_method&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt; Mocha::StubbingError: stubbing method on non-mock object:&lt;/span&gt;
      &lt;span class="comment"&gt;# =&amp;gt;   #&amp;lt;Example:0x593620&amp;gt;.example_method&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;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/BI9gvroSqI8" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/02/09/mocha-configuration</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:3e1842d7-be1c-42d9-8c2b-282f139f277b</id>
    <published>2009-02-03T20:49:28+00:00</published>
    <updated>2009-02-03T20:49:28+00:00</updated>
    <title type="html">Mocha Internals under Scrutiny</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/2dFeuqYl8Zo/mocha-internals-under-scrutiny" rel="alternate" type="text/html" />
    <category term="mocha" scheme="http://blog.floehopper.org/articles/tag/mocha" />
    <category term="internals" scheme="http://blog.floehopper.org/articles/tag/internals" />
    <category term="implementation" scheme="http://blog.floehopper.org/articles/tag/implementation" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="ioke" scheme="http://blog.floehopper.org/articles/tag/ioke" />
    <summary type="html">&lt;p&gt;I&amp;#8217;ve just read Brian Guthrie&amp;#8217;s recent article entitled &lt;a href="http://blog.brianguthrie.com/articles/2009/02/03/ioke-mocking-mocha-as-exemplar"&gt;Ioke mocking, Mocha as exemplar&lt;/a&gt;. Brian has volunteered to work on a mocking framework for &lt;a href="http://olabini.com/"&gt;Ola Bini&amp;#8217;s&lt;/a&gt; &lt;a href="http://ioke.org/"&gt;Ioke&lt;/a&gt;. I&amp;#8217;ve read bits and pieces on Ola&amp;#8217;s blog about the development of Ioke, so I was very interested to see what Brian had to say. He makes some very valid comments; both about mocking in general and about the internals of &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Mocking in General&lt;/h3&gt;


	&lt;p&gt;I agree with him about it being so easy to stub in prototype-based languages, but (as he says) mocking libraries offer more than just stubbing. One related problem is that different people mean different things when they talk about &amp;#8220;mocking&amp;#8221;. &lt;a href="http://xunitpatterns.com/"&gt;xUnit Test Patterns&lt;/a&gt; by Gerard Meszaros provides a useful breakdown of the different capabilities offered by different types of what he (more generically) calls &lt;a href="http://xunitpatterns.com/Test%20Double%20Patterns.html"&gt;Test Doubles&lt;/a&gt; :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Dummy Object&lt;/li&gt;
		&lt;li&gt;Test Stub&lt;/li&gt;
		&lt;li&gt;Test Spy&lt;/li&gt;
		&lt;li&gt;Mock Object&lt;/li&gt;
		&lt;li&gt;Fake Object&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;In my &lt;a href="http://lrug.org"&gt;&lt;span class="caps"&gt;LRUG&lt;/span&gt;&lt;/a&gt; presentation: &lt;a href="http://blog.floehopper.org/presentations/lrug-mock-objects-2007-07-09/#slide7"&gt;An Introduction to Mock Objects in Ruby&lt;/a&gt;, I translated these different types of Test Doubles into Ruby examples which people might find helpful.&lt;/p&gt;


	&lt;h3&gt;Mocha Internals&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m glad that &lt;a href="http://blog.brianguthrie.com/"&gt;Brian&lt;/a&gt; drew some inspiration from reading the Mocha source code &amp;#8211; I have to admit I went through a similar exercise with the &lt;a href="http://www.jmock.org/"&gt;jMock&lt;/a&gt; source code some time ago. So thanks to &lt;a href="http://www.natpryce.com/"&gt;Nat&lt;/a&gt; &amp;#38; &lt;a href="http://www.m3p.co.uk/"&gt;Steve&lt;/a&gt; for that.&lt;/p&gt;


	&lt;p&gt;Mocha (particularly the internals) has changed a lot since the early releases but, as Brian mentions, the original split between the so-called Mocha and Stubba components has not really been bridged internally. Reading this critique has just helped me realise that a mock object in Ruby is, after all, just an instance of a &lt;a href="http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc"&gt;BlankSlate-like&lt;/a&gt; object and could therefore be approached with Stubba-like tactics (rather than the specialised Mocha-like tactics which are currently used). I think this could lead to a significant simplification of the code. Yay! I love open source :-)&lt;/p&gt;


	&lt;p&gt;As well as the welcome critique, Brian made some very pleasing comments :-&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;I’d happily recommend [Mocha] to others as a good example of how to pull off some hairy Ruby functionality without writing a whole lot of hairy Ruby code in the process.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Much of Mocha is like that: moderately sized, neither opaque in its density or transparent in its verbosity. Nice, I suppose, for my own definition of nice.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;h3&gt;Reflections&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m a fan of the &lt;a href="http://www.pragprog.com/"&gt;Pragmatic Programmers&lt;/a&gt; suggestion to &amp;#8220;learn a new programming language every year&amp;#8221;. As an extension to this, I think there is some truth in what I think is a quote from &lt;a href="http://dannorth.net/"&gt;Dan North&lt;/a&gt; : &amp;#8220;everyone should write a mocking framework&amp;#8221;. In any case, I certainly know that one of the most important things I&amp;#8217;ve got out of writing Mocha is a deeper understanding of Ruby internals.&lt;/p&gt;


	&lt;p&gt;Lastly this seems like an opportune time to thank my former colleagues at Reevoo: &lt;a href="http://po-ru.com/"&gt;Paul Battley&lt;/a&gt;, &lt;a href="http://chrisroos.co.uk/"&gt;Chris Roos&lt;/a&gt; and especially &lt;a href="http://www.techbelly.com/"&gt;Ben Griffiths&lt;/a&gt; for all their help and encouragement with Mocha.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I&amp;#8217;ve just read Brian Guthrie&amp;#8217;s recent article entitled &lt;a href="http://blog.brianguthrie.com/articles/2009/02/03/ioke-mocking-mocha-as-exemplar"&gt;Ioke mocking, Mocha as exemplar&lt;/a&gt;. Brian has volunteered to work on a mocking framework for &lt;a href="http://olabini.com/"&gt;Ola Bini&amp;#8217;s&lt;/a&gt; &lt;a href="http://ioke.org/"&gt;Ioke&lt;/a&gt;. I&amp;#8217;ve read bits and pieces on Ola&amp;#8217;s blog about the development of Ioke, so I was very interested to see what Brian had to say. He makes some very valid comments; both about mocking in general and about the internals of &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Mocking in General&lt;/h3&gt;


	&lt;p&gt;I agree with him about it being so easy to stub in prototype-based languages, but (as he says) mocking libraries offer more than just stubbing. One related problem is that different people mean different things when they talk about &amp;#8220;mocking&amp;#8221;. &lt;a href="http://xunitpatterns.com/"&gt;xUnit Test Patterns&lt;/a&gt; by Gerard Meszaros provides a useful breakdown of the different capabilities offered by different types of what he (more generically) calls &lt;a href="http://xunitpatterns.com/Test%20Double%20Patterns.html"&gt;Test Doubles&lt;/a&gt; :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Dummy Object&lt;/li&gt;
		&lt;li&gt;Test Stub&lt;/li&gt;
		&lt;li&gt;Test Spy&lt;/li&gt;
		&lt;li&gt;Mock Object&lt;/li&gt;
		&lt;li&gt;Fake Object&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;In my &lt;a href="http://lrug.org"&gt;&lt;span class="caps"&gt;LRUG&lt;/span&gt;&lt;/a&gt; presentation: &lt;a href="http://blog.floehopper.org/presentations/lrug-mock-objects-2007-07-09/#slide7"&gt;An Introduction to Mock Objects in Ruby&lt;/a&gt;, I translated these different types of Test Doubles into Ruby examples which people might find helpful.&lt;/p&gt;


	&lt;h3&gt;Mocha Internals&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m glad that &lt;a href="http://blog.brianguthrie.com/"&gt;Brian&lt;/a&gt; drew some inspiration from reading the Mocha source code &amp;#8211; I have to admit I went through a similar exercise with the &lt;a href="http://www.jmock.org/"&gt;jMock&lt;/a&gt; source code some time ago. So thanks to &lt;a href="http://www.natpryce.com/"&gt;Nat&lt;/a&gt; &amp;#38; &lt;a href="http://www.m3p.co.uk/"&gt;Steve&lt;/a&gt; for that.&lt;/p&gt;


	&lt;p&gt;Mocha (particularly the internals) has changed a lot since the early releases but, as Brian mentions, the original split between the so-called Mocha and Stubba components has not really been bridged internally. Reading this critique has just helped me realise that a mock object in Ruby is, after all, just an instance of a &lt;a href="http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc"&gt;BlankSlate-like&lt;/a&gt; object and could therefore be approached with Stubba-like tactics (rather than the specialised Mocha-like tactics which are currently used). I think this could lead to a significant simplification of the code. Yay! I love open source :-)&lt;/p&gt;


	&lt;p&gt;As well as the welcome critique, Brian made some very pleasing comments :-&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;I’d happily recommend [Mocha] to others as a good example of how to pull off some hairy Ruby functionality without writing a whole lot of hairy Ruby code in the process.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Much of Mocha is like that: moderately sized, neither opaque in its density or transparent in its verbosity. Nice, I suppose, for my own definition of nice.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;h3&gt;Reflections&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m a fan of the &lt;a href="http://www.pragprog.com/"&gt;Pragmatic Programmers&lt;/a&gt; suggestion to &amp;#8220;learn a new programming language every year&amp;#8221;. As an extension to this, I think there is some truth in what I think is a quote from &lt;a href="http://dannorth.net/"&gt;Dan North&lt;/a&gt; : &amp;#8220;everyone should write a mocking framework&amp;#8221;. In any case, I certainly know that one of the most important things I&amp;#8217;ve got out of writing Mocha is a deeper understanding of Ruby internals.&lt;/p&gt;


	&lt;p&gt;Lastly this seems like an opportune time to thank my former colleagues at Reevoo: &lt;a href="http://po-ru.com/"&gt;Paul Battley&lt;/a&gt;, &lt;a href="http://chrisroos.co.uk/"&gt;Chris Roos&lt;/a&gt; and especially &lt;a href="http://www.techbelly.com/"&gt;Ben Griffiths&lt;/a&gt; for all their help and encouragement with Mocha.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/2dFeuqYl8Zo" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/02/03/mocha-internals-under-scrutiny</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:908e5794-c71e-4c1a-9f95-144c20a1f0f0</id>
    <published>2009-02-02T17:12:54+00:00</published>
    <updated>2009-02-03T10:08:55+00:00</updated>
    <title type="html">Test::Unit and MiniTest with different Ruby versions</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/lRqoPwmGO8s/test-unit-and-minitest-with-different-ruby-versions" rel="alternate" type="text/html" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="testing" scheme="http://blog.floehopper.org/articles/tag/testing" />
    <category term="testunit" scheme="http://blog.floehopper.org/articles/tag/testunit" />
    <category term="minitest" scheme="http://blog.floehopper.org/articles/tag/minitest" />
    <category term="miniunit" scheme="http://blog.floehopper.org/articles/tag/miniunit" />
    <category term="version" scheme="http://blog.floehopper.org/articles/tag/version" />
    <category term="1.8" scheme="http://blog.floehopper.org/articles/tag/1.8" />
    <category term="1.9.0" scheme="http://blog.floehopper.org/articles/tag/1.9.0" />
    <category term="1.9.1" scheme="http://blog.floehopper.org/articles/tag/1.9.1" />
    <summary type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In recent weeks, I&amp;#8217;ve been trying to ensure that &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; works with the new versions of Ruby as well as &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, the &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; replacement. I started &lt;a href="http://twitter.com/floehopper/status/1155022088"&gt;getting very confused&lt;/a&gt; with all the different ways to write/run tests, so I made some notes for myself. In the wake of the &lt;a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/35e963933f9d0b1a"&gt;release of Ruby 1.9.1&lt;/a&gt;, I thought these notes might be useful to others &amp;#8211; so here they are.&lt;/p&gt;


	&lt;p&gt;I haven&amp;#8217;t got into the MiniTest::Spec or MiniTest::Mock side of things, nor have I looked at other testing libraries like &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;, &lt;a href="http://thoughtbot.com/projects/shoulda/"&gt;Shoulda&lt;/a&gt;, &lt;a href="http://test-spec.rubyforge.org/"&gt;Test/Spec&lt;/a&gt;, etc. Please let me know if you see any errors or omissions and I&amp;#8217;ll update this article.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve included the information about Ruby 1.9.0 for completeness, but most people will only be interested in &lt;a href="#vanilla-ruby1.9.1"&gt;the sections on 1.9.1&lt;/a&gt; which is the &amp;#8220;first stable release of Ruby 1.9 series&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;As I mentioned in the &lt;a href="http://blog.floehopper.org/articles/2009/02/01/mocha-release-0-9-5"&gt;release notes&lt;/a&gt;, Mocha 0.9.5 should work with Test::Unit or MiniTest in Ruby 1.8.* or Ruby 1.9.1. It does not currently work in Ruby 1.9.0, but I won&amp;#8217;t be making this a priority unless I have specific requests to do so.&lt;/p&gt;


	&lt;p&gt;Note that at some point MiniTest changed its name from MiniUnit.&lt;/p&gt;


	&lt;h3&gt;Ruby 1.8 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;The basics.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.8 with MiniTest gem&lt;/h3&gt;


	&lt;p&gt;If you can&amp;#8217;t upgrade to Ruby 1.9, you can still use MiniTest by installing the gem. Note that you have to install the autorun exit hook manually for MiniTest &amp;#8211; this is done automatically for Test::Unit when you require &amp;#8216;test/unit&amp;#8217; &amp;#8211; if you want the tests to be executed when the file run as a Ruby script.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# gem install minitest&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="constant"&gt;MiniTest&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;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18MiniTestGemTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;MiniTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="minitest-tu-shim"&gt;Ruby 1.8 with MiniTest-Test::Unit shim&lt;/h3&gt;


	&lt;p&gt;This takes things a step further by installing a shim gem which makes requiring &amp;#8216;test/unit&amp;#8217; behave the same way as it does in a &lt;a href="#vanilla-ruby1.9.1"&gt;vanilla Ruby 1.9.1 installation&lt;/a&gt; i.e. Test::Unit becomes a thin wrapper around MiniTest. This means that you don&amp;#8217;t have to change your tests to inherit from MiniTest::Unit::TestCase in order to use MiniTest. However, you should note that some of Test::Unit&amp;#8217;s &lt;span class="caps"&gt;API&lt;/span&gt; (e.g. Test::Unit::TestResult) is no longer available. Note that you can reverse the effect of &lt;code&gt;use_minitest yes&lt;/code&gt; using &lt;code&gt;use_minitest no&lt;/code&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# sudo gem install minitest_tu_shim&lt;/span&gt;
  &lt;span class="comment"&gt;# sudo use_minitest yes&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18MiniTestTUShimTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.0 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;The Test::Unit standard library seems to be unchanged.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby190TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.0 with Mini::Test standard library&lt;/h3&gt;


	&lt;p&gt;An earlier version of MiniTest (i.e. Mini::Test) is also available as a standard library. Note the different directory, file, class &amp;#38; module names.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;mini/test&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="comment"&gt;# c.f. require 'minitest/unit' in Ruby 1.9.1&lt;/span&gt;

  &lt;span class="constant"&gt;Mini&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="ident"&gt;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby190MiniTestTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Mini&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;TestCase&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="vanilla-ruby1.9.1"&gt;Ruby 1.9.1 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;Test::Unit is just a thin wrapper around MiniTest as described in &lt;a href="#minitest-tu-shim"&gt;Ruby 1.8 with MiniTest-Test::Unit shim&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;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby191TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.1 with MiniTest standard library&lt;/h3&gt;


	&lt;p&gt;MiniTest is intended to be the default standard library to use for testing.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="constant"&gt;MiniTest&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;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby191MiniTestTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;MiniTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.1 with Test::Unit gem&lt;/h3&gt;


	&lt;p&gt;It is possible to use the &lt;em&gt;classic&lt;/em&gt; Test::Unit by installing the gem. It looks like you need to specify version 1.2.3 to avoid picking up what appears to be some more significant changes in versions &amp;gt;= 2.0.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# sudo gem install test-unit -v 1.2.3&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test-unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby19TestUnitGemTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Versions used for testing&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.apple.com/macosx/"&gt;&lt;span class="caps"&gt;OSX&lt;/span&gt;&lt;/a&gt; Leopard 10.5.6&lt;/li&gt;
		&lt;li&gt;Ruby 1.8.6 (2008-08-11 patchlevel 287)&lt;/li&gt;
		&lt;li&gt;Ruby 1.9.0 (2008-10-04 revision 19669)&lt;/li&gt;
		&lt;li&gt;Ruby 1.9.1p0 (2009-01-30 revision 21907)&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://blog.zenspider.com/2009/01/minitest-version-131-has-been.html"&gt;minitest&lt;/a&gt; gem 1.3.1&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://blog.zenspider.com/2008/10/minitest-tu-shim-version-130-h.html"&gt;minitest_tu_shim&lt;/a&gt; gem 1.3.0&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit&lt;/a&gt; gem 1.2.3&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;References&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://markmail.org/message/zm5ocf3koijgrto2"&gt;test/unit and minitest&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://groups.google.vg/group/ruby-talk-google/browse_thread/thread/317778a91b31f142/ac507e6ae948c5d3"&gt;MiniTest &amp;#38; Test::Unit::TestResult in Ruby 1.9.1&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://groups.google.vg/group/ruby-talk-google/browse_thread/thread/212b92cc7df43b80/dbe74a7aa8b16ab5"&gt;MiniTest / Test::Unit&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;</summary>
    <content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;In recent weeks, I&amp;#8217;ve been trying to ensure that &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; works with the new versions of Ruby as well as &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;, the &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; replacement. I started &lt;a href="http://twitter.com/floehopper/status/1155022088"&gt;getting very confused&lt;/a&gt; with all the different ways to write/run tests, so I made some notes for myself. In the wake of the &lt;a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/35e963933f9d0b1a"&gt;release of Ruby 1.9.1&lt;/a&gt;, I thought these notes might be useful to others &amp;#8211; so here they are.&lt;/p&gt;


	&lt;p&gt;I haven&amp;#8217;t got into the MiniTest::Spec or MiniTest::Mock side of things, nor have I looked at other testing libraries like &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;, &lt;a href="http://thoughtbot.com/projects/shoulda/"&gt;Shoulda&lt;/a&gt;, &lt;a href="http://test-spec.rubyforge.org/"&gt;Test/Spec&lt;/a&gt;, etc. Please let me know if you see any errors or omissions and I&amp;#8217;ll update this article.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve included the information about Ruby 1.9.0 for completeness, but most people will only be interested in &lt;a href="#vanilla-ruby1.9.1"&gt;the sections on 1.9.1&lt;/a&gt; which is the &amp;#8220;first stable release of Ruby 1.9 series&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;As I mentioned in the &lt;a href="http://blog.floehopper.org/articles/2009/02/01/mocha-release-0-9-5"&gt;release notes&lt;/a&gt;, Mocha 0.9.5 should work with Test::Unit or MiniTest in Ruby 1.8.* or Ruby 1.9.1. It does not currently work in Ruby 1.9.0, but I won&amp;#8217;t be making this a priority unless I have specific requests to do so.&lt;/p&gt;


	&lt;p&gt;Note that at some point MiniTest changed its name from MiniUnit.&lt;/p&gt;


	&lt;h3&gt;Ruby 1.8 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;The basics.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.8 with MiniTest gem&lt;/h3&gt;


	&lt;p&gt;If you can&amp;#8217;t upgrade to Ruby 1.9, you can still use MiniTest by installing the gem. Note that you have to install the autorun exit hook manually for MiniTest &amp;#8211; this is done automatically for Test::Unit when you require &amp;#8216;test/unit&amp;#8217; &amp;#8211; if you want the tests to be executed when the file run as a Ruby script.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# gem install minitest&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="constant"&gt;MiniTest&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;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18MiniTestGemTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;MiniTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="minitest-tu-shim"&gt;Ruby 1.8 with MiniTest-Test::Unit shim&lt;/h3&gt;


	&lt;p&gt;This takes things a step further by installing a shim gem which makes requiring &amp;#8216;test/unit&amp;#8217; behave the same way as it does in a &lt;a href="#vanilla-ruby1.9.1"&gt;vanilla Ruby 1.9.1 installation&lt;/a&gt; i.e. Test::Unit becomes a thin wrapper around MiniTest. This means that you don&amp;#8217;t have to change your tests to inherit from MiniTest::Unit::TestCase in order to use MiniTest. However, you should note that some of Test::Unit&amp;#8217;s &lt;span class="caps"&gt;API&lt;/span&gt; (e.g. Test::Unit::TestResult) is no longer available. Note that you can reverse the effect of &lt;code&gt;use_minitest yes&lt;/code&gt; using &lt;code&gt;use_minitest no&lt;/code&gt;.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# sudo gem install minitest_tu_shim&lt;/span&gt;
  &lt;span class="comment"&gt;# sudo use_minitest yes&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby18MiniTestTUShimTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.0 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;The Test::Unit standard library seems to be unchanged.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby190TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.0 with Mini::Test standard library&lt;/h3&gt;


	&lt;p&gt;An earlier version of MiniTest (i.e. Mini::Test) is also available as a standard library. Note the different directory, file, class &amp;#38; module names.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;mini/test&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt; &lt;span class="comment"&gt;# c.f. require 'minitest/unit' in Ruby 1.9.1&lt;/span&gt;

  &lt;span class="constant"&gt;Mini&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="ident"&gt;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby190MiniTestTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;Mini&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;TestCase&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3 id="vanilla-ruby1.9.1"&gt;Ruby 1.9.1 with Test::Unit standard library&lt;/h3&gt;


	&lt;p&gt;Test::Unit is just a thin wrapper around MiniTest as described in &lt;a href="#minitest-tu-shim"&gt;Ruby 1.8 with MiniTest-Test::Unit shim&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;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby191TestUnitTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.1 with MiniTest standard library&lt;/h3&gt;


	&lt;p&gt;MiniTest is intended to be the default standard library to use for testing.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;minitest/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="constant"&gt;MiniTest&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;autorun&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby191MiniTestTest&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;MiniTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Ruby 1.9.1 with Test::Unit gem&lt;/h3&gt;


	&lt;p&gt;It is possible to use the &lt;em&gt;classic&lt;/em&gt; Test::Unit by installing the gem. It looks like you need to specify version 1.2.3 to avoid picking up what appears to be some more significant changes in versions &amp;gt;= 2.0.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# sudo gem install test-unit -v 1.2.3&lt;/span&gt;

  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test-unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;test/unit&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;

  &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Ruby19TestUnitGemTest&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;h3&gt;Versions used for testing&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.apple.com/macosx/"&gt;&lt;span class="caps"&gt;OSX&lt;/span&gt;&lt;/a&gt; Leopard 10.5.6&lt;/li&gt;
		&lt;li&gt;Ruby 1.8.6 (2008-08-11 patchlevel 287)&lt;/li&gt;
		&lt;li&gt;Ruby 1.9.0 (2008-10-04 revision 19669)&lt;/li&gt;
		&lt;li&gt;Ruby 1.9.1p0 (2009-01-30 revision 21907)&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://blog.zenspider.com/2009/01/minitest-version-131-has-been.html"&gt;minitest&lt;/a&gt; gem 1.3.1&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://blog.zenspider.com/2008/10/minitest-tu-shim-version-130-h.html"&gt;minitest_tu_shim&lt;/a&gt; gem 1.3.0&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit&lt;/a&gt; gem 1.2.3&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;References&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://markmail.org/message/zm5ocf3koijgrto2"&gt;test/unit and minitest&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://groups.google.vg/group/ruby-talk-google/browse_thread/thread/317778a91b31f142/ac507e6ae948c5d3"&gt;MiniTest &amp;#38; Test::Unit::TestResult in Ruby 1.9.1&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://groups.google.vg/group/ruby-talk-google/browse_thread/thread/212b92cc7df43b80/dbe74a7aa8b16ab5"&gt;MiniTest / Test::Unit&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/lRqoPwmGO8s" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/02/02/test-unit-and-minitest-with-different-ruby-versions</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:80fb6569-0091-4906-ab35-769a5d1e46a7</id>
    <published>2009-02-01T12:55:57+00:00</published>
    <updated>2009-02-01T12:57:19+00:00</updated>
    <title type="html">Mocha Release 0.9.5</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/SyfMmt_PY9Y/mocha-release-0-9-5" rel="alternate" type="text/html" />
    <category term="mocha_release" scheme="http://blog.floehopper.org/articles/category/mocha_release" label="mocha_release" />
    <category term="mocha" scheme="http://blog.floehopper.org/articles/tag/mocha" />
    <category term="mock" scheme="http://blog.floehopper.org/articles/tag/mock" />
    <category term="stub" scheme="http://blog.floehopper.org/articles/tag/stub" />
    <category term="ruby" scheme="http://blog.floehopper.org/articles/tag/ruby" />
    <category term="testing" scheme="http://blog.floehopper.org/articles/tag/testing" />
    <category term="tdd" scheme="http://blog.floehopper.org/articles/tag/tdd" />
    <summary type="html">&lt;h3&gt;Ruby 1.9 Compatibility&lt;/h3&gt;


	&lt;p&gt;Note that &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; should be compatible with Ruby 1.9.1 using MiniTest or &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;. However, if you want to use &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;, you will need to install the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/32"&gt;Lighthouse bug #32&lt;/a&gt; &amp;#8211; stub_everything should mean mock responds to anything.&lt;/li&gt;
		&lt;li&gt;Added &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000035"&gt;Expectation#twice&lt;/a&gt; to improve readability. Thanks to pull request from &lt;a href="http://tinogomes.wordpress.com/"&gt;Celestino Gomes&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;In Ruby 1.9.1, requiring &amp;#8216;test/unit&amp;#8217; loads a thin wrapper around MiniTest and &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/TestCase.html"&gt;Test::Unit::TestCase&lt;/a&gt; ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; modules more than once to avoid nasty consequences. Thanks to &lt;a href="http://matthiashennemeyer.com/"&gt;Matthias Hennemeyer&lt;/a&gt; for help with this.&lt;/li&gt;
		&lt;li&gt;Ruby 1.9 includes rake, but not rake/contrib. For the moment I&amp;#8217;ve moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to &lt;a href="http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9"&gt;build a rake/contrib gem&lt;/a&gt; or similar to get this working properly.&lt;/li&gt;
	&lt;/ul&gt;</summary>
    <content type="html">&lt;h3&gt;Ruby 1.9 Compatibility&lt;/h3&gt;


	&lt;p&gt;Note that &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; should be compatible with Ruby 1.9.1 using MiniTest or &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;. However, if you want to use &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html"&gt;Test::Unit&lt;/a&gt;, you will need to install the &lt;a href="http://test-unit.rubyforge.org/"&gt;test-unit gem&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Release Notes&lt;/h3&gt;


	&lt;ul&gt;
	&lt;li&gt;Fixed &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/32"&gt;Lighthouse bug #32&lt;/a&gt; &amp;#8211; stub_everything should mean mock responds to anything.&lt;/li&gt;
		&lt;li&gt;Added &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Expectation.html#M000035"&gt;Expectation#twice&lt;/a&gt; to improve readability. Thanks to pull request from &lt;a href="http://tinogomes.wordpress.com/"&gt;Celestino Gomes&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;In Ruby 1.9.1, requiring &amp;#8216;test/unit&amp;#8217; loads a thin wrapper around MiniTest and &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/TestCase.html"&gt;Test::Unit::TestCase&lt;/a&gt; ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the &lt;a href="http://mocha.rubyforge.org"&gt;Mocha&lt;/a&gt; modules more than once to avoid nasty consequences. Thanks to &lt;a href="http://matthiashennemeyer.com/"&gt;Matthias Hennemeyer&lt;/a&gt; for help with this.&lt;/li&gt;
		&lt;li&gt;Ruby 1.9 includes rake, but not rake/contrib. For the moment I&amp;#8217;ve moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to &lt;a href="http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9"&gt;build a rake/contrib gem&lt;/a&gt; or similar to get this working properly.&lt;/li&gt;
	&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/SyfMmt_PY9Y" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/02/01/mocha-release-0-9-5</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:4839fb58-4c08-4c25-9264-3f18729fd711</id>
    <published>2009-01-22T19:20:38+00:00</published>
    <updated>2009-01-22T19:25:17+00:00</updated>
    <title type="html">Climbing Back onto the Java Horse</title>
    <link href="http://feeds.floehopper.org/~r/floehopper-blog/~3/mKSi5Yk57ek/climbing-back-onto-the-java-horse" rel="alternate" type="text/html" />
    <category term="java" scheme="http://blog.floehopper.org/articles/tag/java" />
    <category term="junit" scheme="http://blog.floehopper.org/articles/tag/junit" />
    <category term="jmock" scheme="http://blog.floehopper.org/articles/tag/jmock" />
    <category term="eclipse" scheme="http://blog.floehopper.org/articles/tag/eclipse" />
    <category term="osx" scheme="http://blog.floehopper.org/articles/tag/osx" />
    <category term="leopard" scheme="http://blog.floehopper.org/articles/tag/leopard" />
    <summary type="html">&lt;p&gt;I took a short break from job-hunting&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; earlier today to see if I could still write &lt;a href="http://java.sun.com/"&gt;Java&lt;/a&gt; code. After my &lt;a href="http://blog.floehopper.org/articles/2008/03/17/java-rehabilitation-clinic"&gt;Java rehab&lt;/a&gt; which consisted of 3+ years of writing &lt;a href="http://www.ruby-lang.org/"&gt;Ruby&lt;/a&gt;, I was a bit unsure how much Java I would remember. To get started, I decided to try and set up &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; on my MacBook Pro. I ran into a few problems which I thought I&amp;#8217;d document here in case it helps anyone else.&lt;/p&gt;


	&lt;h3&gt;Installing Eclipse&lt;/h3&gt;


	&lt;p&gt;I downloaded the Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; version of &amp;#8220;Eclipse &lt;span class="caps"&gt;IDE&lt;/span&gt; for Java EE&lt;sup&gt;&lt;a href="#fn2"&gt;2&lt;/a&gt;&lt;/sup&gt; Developers&amp;#8221; from the &lt;a href="http://www.eclipse.org/downloads/"&gt;Eclipse Downloads page&lt;/a&gt; and unpacked it into my Applications directory. For the record, I was running &lt;span class="caps"&gt;OSX 10&lt;/span&gt;.5.6 and downloaded version 3.4.1 of Eclipse.&lt;/p&gt;


	&lt;p&gt;But when I double-clicked to start the application, I got the following error message:-&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.flickr.com/photos/jamesthecat/3217546063/" title="eclipse-java-environment-startup-error by floehopper, on Flickr"&gt;
  &lt;img src="http://farm4.static.flickr.com/3335/3217546063_79751cf5c9_o.png" width="356" height="170" alt="eclipse-java-environment-startup-error" /&gt;
&lt;/a&gt;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No virtual machine was found after searching the following locations: etc, etc.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;However, I was able to run the application from the command-line, which pointed to an environment problem. Reading the &amp;#8220;Cannot find a VM&amp;#8221; section of &lt;a href="http://wiki.eclipse.org/FAQ_I_unzipped_Eclipse%2C_but_it_won%27t_start._Why%3F"&gt;I unzipped Eclipse, but it won&amp;#8217;t start. Why?&lt;/a&gt;, I decided I needed to explicitly specify the location of the &lt;span class="caps"&gt;JVM&lt;/span&gt;. It turned out there were a few gotchas. The &lt;span class="caps"&gt;OSX&lt;/span&gt;-specific bit of the &lt;a href="http://www.eclipse.org/eclipse/development/readme_eclipse_3.4.1.html#macosx"&gt;installation &lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt; explains how to edit the &lt;code&gt;eclipse.ini&lt;/code&gt; file within the Eclipse application bundle. &lt;a href="http://wiki.eclipse.org/Eclipse.ini"&gt;Eclipsepedia explains&lt;/a&gt; the format of the &lt;code&gt;-vm&lt;/code&gt; option :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;The -vm option and its value (the path) must be on separate lines.&lt;/li&gt;
		&lt;li&gt;The value must be the full absolute path to the Java executable, not just to the Java home directory.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So I added the following to my &lt;code&gt;eclipse.ini&lt;/code&gt; and the application started up successfully :-&lt;/p&gt;


&lt;pre&gt;
  &lt;code&gt;
  -vm
  /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0
  &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;&lt;em&gt;Note: I think that the &lt;code&gt;-vm option&lt;/code&gt; must come before the &lt;code&gt;-vmargs&lt;/code&gt; option.&lt;/em&gt;&lt;/p&gt;


	&lt;h3&gt;JUnit4 and jMock2&lt;/h3&gt;


	&lt;p&gt;Next I decided to see if I could write a test using &lt;a href="http://www.junit.org/"&gt;JUnit&lt;/a&gt; and &lt;a href="http://www.jmock.org/"&gt;jMock&lt;/a&gt; to &lt;a href="http://books.google.co.uk/books?id=gFgnde_vwMAC"&gt;drive out the design&lt;/a&gt; of a simple class. I downloaded the most recent stable version of jMock which was v2.5.1 and added the relevant jars to Eclipse so that they could be included in my project classpath :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;jmock-2.5.1.jar&lt;/li&gt;
		&lt;li&gt;hamcrest-core-1.1.jar&lt;/li&gt;
		&lt;li&gt;hamcrest-library-1.1.jar&lt;/li&gt;
		&lt;li&gt;jmock-junit4-2.5.1.jar&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;At this point everything was going quite smoothly &amp;#8211; especially after I side-stepped some of &lt;a href="http://twitter.com/threedaymonk/status/1138794613"&gt;Java&amp;#8217;s purgatorial nonsense&lt;/a&gt; by re-learning the Eclipse keyboard shortcuts for &amp;#8220;Quick Fix&amp;#8221; and &amp;#8220;Content Assist&amp;#8221;. But now I decided I wanted to try using JUnit Java annotations for my tests :-&lt;/p&gt;


&lt;pre&gt;
  &lt;code&gt;
  import org.junit.Test;
  import org.junit.runner.RunWith;

  import org.jmock.Mockery;
  import org.jmock.Expectations;
  import org.jmock.integration.junit4.JUnit4Mockery;
  import org.jmock.integration.junit4.JMock;

  @RunWith(JMock.class)
  public class PublisherTest {

    Mockery context = new JUnit4Mockery();

    @Test 
    public void oneSubscriberReceivesAMessage() {
      ...
  &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Unfortunately I got this error around the &lt;code&gt;@RunWith(JMock.class)&lt;/code&gt; annotation :-&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;The type org.junit.internal.runners.JUnit4ClassRunner cannot be resolved. It is indirectly referenced from required .class files.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;After bit of &lt;a href="http://dertompson.com/2007/12/12/spring-25-eclipse-and-junit-44/"&gt;Googling&lt;/a&gt;, I worked out that I needed a newer version of JUnit than the one (v4.3.1) that came with Eclipse. So I downloaded JUnit v4.5 and swapped it into the classpath. Problem solved.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; I was made redundant from Reevoo at the end of last year.&lt;/p&gt;


	&lt;p id="fn2"&gt;&lt;sup&gt;2&lt;/sup&gt; Because I love all that &lt;em&gt;enterprise&lt;/em&gt; goodness ;-)&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I took a short break from job-hunting&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; earlier today to see if I could still write &lt;a href="http://java.sun.com/"&gt;Java&lt;/a&gt; code. After my &lt;a href="http://blog.floehopper.org/articles/2008/03/17/java-rehabilitation-clinic"&gt;Java rehab&lt;/a&gt; which consisted of 3+ years of writing &lt;a href="http://www.ruby-lang.org/"&gt;Ruby&lt;/a&gt;, I was a bit unsure how much Java I would remember. To get started, I decided to try and set up &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; on my MacBook Pro. I ran into a few problems which I thought I&amp;#8217;d document here in case it helps anyone else.&lt;/p&gt;


	&lt;h3&gt;Installing Eclipse&lt;/h3&gt;


	&lt;p&gt;I downloaded the Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; version of &amp;#8220;Eclipse &lt;span class="caps"&gt;IDE&lt;/span&gt; for Java EE&lt;sup&gt;&lt;a href="#fn2"&gt;2&lt;/a&gt;&lt;/sup&gt; Developers&amp;#8221; from the &lt;a href="http://www.eclipse.org/downloads/"&gt;Eclipse Downloads page&lt;/a&gt; and unpacked it into my Applications directory. For the record, I was running &lt;span class="caps"&gt;OSX 10&lt;/span&gt;.5.6 and downloaded version 3.4.1 of Eclipse.&lt;/p&gt;


	&lt;p&gt;But when I double-clicked to start the application, I got the following error message:-&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.flickr.com/photos/jamesthecat/3217546063/" title="eclipse-java-environment-startup-error by floehopper, on Flickr"&gt;
  &lt;img src="http://farm4.static.flickr.com/3335/3217546063_79751cf5c9_o.png" width="356" height="170" alt="eclipse-java-environment-startup-error" /&gt;
&lt;/a&gt;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No virtual machine was found after searching the following locations: etc, etc.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;However, I was able to run the application from the command-line, which pointed to an environment problem. Reading the &amp;#8220;Cannot find a VM&amp;#8221; section of &lt;a href="http://wiki.eclipse.org/FAQ_I_unzipped_Eclipse%2C_but_it_won%27t_start._Why%3F"&gt;I unzipped Eclipse, but it won&amp;#8217;t start. Why?&lt;/a&gt;, I decided I needed to explicitly specify the location of the &lt;span class="caps"&gt;JVM&lt;/span&gt;. It turned out there were a few gotchas. The &lt;span class="caps"&gt;OSX&lt;/span&gt;-specific bit of the &lt;a href="http://www.eclipse.org/eclipse/development/readme_eclipse_3.4.1.html#macosx"&gt;installation &lt;span class="caps"&gt;README&lt;/span&gt;&lt;/a&gt; explains how to edit the &lt;code&gt;eclipse.ini&lt;/code&gt; file within the Eclipse application bundle. &lt;a href="http://wiki.eclipse.org/Eclipse.ini"&gt;Eclipsepedia explains&lt;/a&gt; the format of the &lt;code&gt;-vm&lt;/code&gt; option :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;The -vm option and its value (the path) must be on separate lines.&lt;/li&gt;
		&lt;li&gt;The value must be the full absolute path to the Java executable, not just to the Java home directory.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So I added the following to my &lt;code&gt;eclipse.ini&lt;/code&gt; and the application started up successfully :-&lt;/p&gt;


&lt;pre&gt;
  &lt;code&gt;
  -vm
  /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0
  &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;&lt;em&gt;Note: I think that the &lt;code&gt;-vm option&lt;/code&gt; must come before the &lt;code&gt;-vmargs&lt;/code&gt; option.&lt;/em&gt;&lt;/p&gt;


	&lt;h3&gt;JUnit4 and jMock2&lt;/h3&gt;


	&lt;p&gt;Next I decided to see if I could write a test using &lt;a href="http://www.junit.org/"&gt;JUnit&lt;/a&gt; and &lt;a href="http://www.jmock.org/"&gt;jMock&lt;/a&gt; to &lt;a href="http://books.google.co.uk/books?id=gFgnde_vwMAC"&gt;drive out the design&lt;/a&gt; of a simple class. I downloaded the most recent stable version of jMock which was v2.5.1 and added the relevant jars to Eclipse so that they could be included in my project classpath :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;jmock-2.5.1.jar&lt;/li&gt;
		&lt;li&gt;hamcrest-core-1.1.jar&lt;/li&gt;
		&lt;li&gt;hamcrest-library-1.1.jar&lt;/li&gt;
		&lt;li&gt;jmock-junit4-2.5.1.jar&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;At this point everything was going quite smoothly &amp;#8211; especially after I side-stepped some of &lt;a href="http://twitter.com/threedaymonk/status/1138794613"&gt;Java&amp;#8217;s purgatorial nonsense&lt;/a&gt; by re-learning the Eclipse keyboard shortcuts for &amp;#8220;Quick Fix&amp;#8221; and &amp;#8220;Content Assist&amp;#8221;. But now I decided I wanted to try using JUnit Java annotations for my tests :-&lt;/p&gt;


&lt;pre&gt;
  &lt;code&gt;
  import org.junit.Test;
  import org.junit.runner.RunWith;

  import org.jmock.Mockery;
  import org.jmock.Expectations;
  import org.jmock.integration.junit4.JUnit4Mockery;
  import org.jmock.integration.junit4.JMock;

  @RunWith(JMock.class)
  public class PublisherTest {

    Mockery context = new JUnit4Mockery();

    @Test 
    public void oneSubscriberReceivesAMessage() {
      ...
  &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Unfortunately I got this error around the &lt;code&gt;@RunWith(JMock.class)&lt;/code&gt; annotation :-&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;The type org.junit.internal.runners.JUnit4ClassRunner cannot be resolved. It is indirectly referenced from required .class files.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;After bit of &lt;a href="http://dertompson.com/2007/12/12/spring-25-eclipse-and-junit-44/"&gt;Googling&lt;/a&gt;, I worked out that I needed a newer version of JUnit than the one (v4.3.1) that came with Eclipse. So I downloaded JUnit v4.5 and swapped it into the classpath. Problem solved.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; I was made redundant from Reevoo at the end of last year.&lt;/p&gt;


	&lt;p id="fn2"&gt;&lt;sup&gt;2&lt;/sup&gt; Because I love all that &lt;em&gt;enterprise&lt;/em&gt; goodness ;-)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/mKSi5Yk57ek" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/01/22/climbing-back-onto-the-java-horse</feedburner:origLink></entry>
</feed>
