<?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.feedburner.com/~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-11-02T16:23:13+00:00</updated>
  <link rel="self" href="http://feeds.feedburner.com/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:241da9d4-d57a-4197-bc68-74dfa03cc09c</id>
    <published>2009-11-02T16:21:44+00:00</published>
    <updated>2009-11-02T16:23:13+00:00</updated>
    <title type="html">ActiveRecord Model Class Name Clash</title>
    <link href="http://feedproxy.google.com/~r/floehopper-blog/~3/BBCWIIYBaHA/activerecord-model-class-name-clash" rel="alternate" type="text/html" />
    <category term="activerecord" scheme="http://blog.floehopper.org/articles/tag/activerecord" />
    <category term="model" scheme="http://blog.floehopper.org/articles/tag/model" />
    <category term="class" scheme="http://blog.floehopper.org/articles/tag/class" />
    <category term="validation" scheme="http://blog.floehopper.org/articles/tag/validation" />
    <category term="twice" scheme="http://blog.floehopper.org/articles/tag/twice" />
    <category term="callback" scheme="http://blog.floehopper.org/articles/tag/callback" />
    <category term="collision" scheme="http://blog.floehopper.org/articles/tag/collision" />
    <category term="clash" scheme="http://blog.floehopper.org/articles/tag/clash" />
    <summary type="html">&lt;p&gt;I&amp;#8217;ve just spent way too long trying to work out why the validation callbacks were getting called twice on one of my &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html"&gt;ActiveRecord&lt;/a&gt; models. I thought I&amp;#8217;d write this up in case it saves someone else some pain.&lt;/p&gt;


	&lt;p&gt;In the end, I narrowed the problem down to the name of the model class which is &lt;code&gt;Sync&lt;/code&gt;. I should&amp;#8217;ve thought of this sooner, but it turns out there is a Ruby standard library class called &lt;a href="http://ruby-doc.org/stdlib/libdoc/sync/rdoc/index.html"&gt;&lt;code&gt;Sync&lt;/code&gt;&lt;/a&gt;. I haven&amp;#8217;t delved any further into why validation was being called twice. As far as I&amp;#8217;m concerned, once you re-open an existing Ruby class like this, it makes sense that all bets are off.&lt;/p&gt;


	&lt;p&gt;However, I am a bit confused why the original Sync model class definition didn&amp;#8217;t give a &amp;#8220;superclass mismatch&amp;#8221; &lt;a href="http://ruby-doc.org/core/classes/TypeError.html"&gt;&lt;code&gt;TypeError&lt;/code&gt;&lt;/a&gt;, which is what happens if I do :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;script&lt;/span&gt;&lt;span class="punct"&gt;/&lt;/span&gt;&lt;span class="ident"&gt;runner&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;class Sync &amp;lt; ActiveRecord::Base; end&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;It must be a load order issue, since if I put the class definition in a file in app/models, I don&amp;#8217;t see the &lt;code&gt;TypeError&lt;/code&gt;. It would&amp;#8217;ve saved a lot of time if my &lt;code&gt;Sync&lt;/code&gt; model class definition had failed fast in this way. I might see if there&amp;#8217;s a way to make that happen.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I&amp;#8217;ve just spent way too long trying to work out why the validation callbacks were getting called twice on one of my &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html"&gt;ActiveRecord&lt;/a&gt; models. I thought I&amp;#8217;d write this up in case it saves someone else some pain.&lt;/p&gt;


	&lt;p&gt;In the end, I narrowed the problem down to the name of the model class which is &lt;code&gt;Sync&lt;/code&gt;. I should&amp;#8217;ve thought of this sooner, but it turns out there is a Ruby standard library class called &lt;a href="http://ruby-doc.org/stdlib/libdoc/sync/rdoc/index.html"&gt;&lt;code&gt;Sync&lt;/code&gt;&lt;/a&gt;. I haven&amp;#8217;t delved any further into why validation was being called twice. As far as I&amp;#8217;m concerned, once you re-open an existing Ruby class like this, it makes sense that all bets are off.&lt;/p&gt;


	&lt;p&gt;However, I am a bit confused why the original Sync model class definition didn&amp;#8217;t give a &amp;#8220;superclass mismatch&amp;#8221; &lt;a href="http://ruby-doc.org/core/classes/TypeError.html"&gt;&lt;code&gt;TypeError&lt;/code&gt;&lt;/a&gt;, which is what happens if I do :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;script&lt;/span&gt;&lt;span class="punct"&gt;/&lt;/span&gt;&lt;span class="ident"&gt;runner&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;class Sync &amp;lt; ActiveRecord::Base; end&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;It must be a load order issue, since if I put the class definition in a file in app/models, I don&amp;#8217;t see the &lt;code&gt;TypeError&lt;/code&gt;. It would&amp;#8217;ve saved a lot of time if my &lt;code&gt;Sync&lt;/code&gt; model class definition had failed fast in this way. I might see if there&amp;#8217;s a way to make that happen.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/BBCWIIYBaHA" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/11/02/activerecord-model-class-name-clash</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:b23f8cdd-771f-46c1-a4bf-bacf541a1291</id>
    <published>2009-09-18T11:35:40+00:00</published>
    <updated>2009-09-18T11:35:40+00:00</updated>
    <title type="html">Mocha NoMethodError / Load order since version 0.9.6</title>
    <link href="http://feedproxy.google.com/~r/floehopper-blog/~3/ZPXS8KRZxoA/mocha-nomethoderror-load-order-since-version-0-9-6" 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="nomethoderror" scheme="http://blog.floehopper.org/articles/tag/nomethoderror" />
    <category term="load" scheme="http://blog.floehopper.org/articles/tag/load" />
    <category term="order" scheme="http://blog.floehopper.org/articles/tag/order" />
    <summary type="html">&lt;p&gt;There have been a number of load order issues since 0.9.6 was released for which I apologise.&lt;/p&gt;


	&lt;p&gt;The key message is that since 0.9.6, you must ensure that your test framework (&lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;) is loaded &lt;strong&gt;before&lt;/strong&gt; &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; is loaded, otherwise &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will not monkey-patch the test framework and calls to the Mocha &lt;span class="caps"&gt;API&lt;/span&gt; will result in &lt;a href="http://www.ruby-doc.org/core/classes/NoMethodError.html"&gt;NoMethodError&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I hope to write this up in more detail soon, but in the meantime here are a couple of useful links :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://railspikes.com/2009/7/29/rails-2-3-3-upgrade-notes/"&gt;Rails 2.3.3 Upgrade Notes&lt;/a&gt; &lt;/li&gt;
		&lt;li&gt;&lt;a href="http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/"&gt;Rails 2.3.3 + Mocha = Confusion&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Please contact us on the &lt;a href="http://groups.google.com/group/mocha-developer"&gt;mailing list&lt;/a&gt; if you have any questions.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;There have been a number of load order issues since 0.9.6 was released for which I apologise.&lt;/p&gt;


	&lt;p&gt;The key message is that since 0.9.6, you must ensure that your test framework (&lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://blog.zenspider.com/minitest/"&gt;MiniTest&lt;/a&gt;) is loaded &lt;strong&gt;before&lt;/strong&gt; &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; is loaded, otherwise &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; will not monkey-patch the test framework and calls to the Mocha &lt;span class="caps"&gt;API&lt;/span&gt; will result in &lt;a href="http://www.ruby-doc.org/core/classes/NoMethodError.html"&gt;NoMethodError&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I hope to write this up in more detail soon, but in the meantime here are a couple of useful links :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://railspikes.com/2009/7/29/rails-2-3-3-upgrade-notes/"&gt;Rails 2.3.3 Upgrade Notes&lt;/a&gt; &lt;/li&gt;
		&lt;li&gt;&lt;a href="http://selfamusementpark.com/blog/2009/07/30/rails233mochaconfusion/"&gt;Rails 2.3.3 + Mocha = Confusion&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Please contact us on the &lt;a href="http://groups.google.com/group/mocha-developer"&gt;mailing list&lt;/a&gt; if you have any questions.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/ZPXS8KRZxoA" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/09/18/mocha-nomethoderror-load-order-since-version-0-9-6</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:61369f37-aabd-489b-b0df-12a07b6fc820</id>
    <published>2009-09-18T11:17:44+00:00</published>
    <updated>2009-09-18T11:17:45+00:00</updated>
    <title type="html">Mocha Release 0.9.8</title>
    <link href="http://feedproxy.google.com/~r/floehopper-blog/~3/boQWys8YpIk/mocha-release-0-9-8" 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;Fixed bug &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/53"&gt;NameError raised when using Mocha as a Rails plug-in&lt;/a&gt;. Since 0.9.6 the Rails plugin has been broken. See &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/53"&gt;bug report&lt;/a&gt; for details. You will need to explicitly load Mocha &lt;strong&gt;after&lt;/strong&gt; the test framework has been loaded, e.g. by adding &amp;#8220;require &amp;#8216;mocha&amp;#8217;&amp;#8221; at the bottom of test/test_helper.rb.&lt;/li&gt;
		&lt;li&gt;Make &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000024"&gt;Mocha::ParameterMatchers#regexp_matches&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000018"&gt;#includes&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000017"&gt;#has_value&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000016"&gt;#has_key&lt;/a&gt; more robust. Thanks to &lt;a href="http://github.com/sander6"&gt;Sander Hartlage&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Allow passing a block to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Configuration.html"&gt;Mocha::Configuration&lt;/a&gt; methods to only change configuration for the duration of the block. Thanks to &lt;a href="http://www.dcmanges.com/blog"&gt;Dan Manges&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Fixed bug &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/51"&gt;doc generation fails in 0.9.7 gem&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Remove rdoc template incorporating google analytics from source control. The file just needs to exist locally and be ignored by source control. This should stop the warning showing up on e.g. &lt;a href="http://runcoderun.com/floehopper/mocha"&gt;RunCodeRun build results&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;Fixed bug &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/53"&gt;NameError raised when using Mocha as a Rails plug-in&lt;/a&gt;. Since 0.9.6 the Rails plugin has been broken. See &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/53"&gt;bug report&lt;/a&gt; for details. You will need to explicitly load Mocha &lt;strong&gt;after&lt;/strong&gt; the test framework has been loaded, e.g. by adding &amp;#8220;require &amp;#8216;mocha&amp;#8217;&amp;#8221; at the bottom of test/test_helper.rb.&lt;/li&gt;
		&lt;li&gt;Make &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000024"&gt;Mocha::ParameterMatchers#regexp_matches&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000018"&gt;#includes&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000017"&gt;#has_value&lt;/a&gt;, &lt;a href="http://mocha.rubyforge.org/classes/Mocha/ParameterMatchers.html#M000016"&gt;#has_key&lt;/a&gt; more robust. Thanks to &lt;a href="http://github.com/sander6"&gt;Sander Hartlage&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Allow passing a block to &lt;a href="http://mocha.rubyforge.org/classes/Mocha/Configuration.html"&gt;Mocha::Configuration&lt;/a&gt; methods to only change configuration for the duration of the block. Thanks to &lt;a href="http://www.dcmanges.com/blog"&gt;Dan Manges&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Fixed bug &lt;a href="http://floehopper.lighthouseapp.com/projects/22289/tickets/51"&gt;doc generation fails in 0.9.7 gem&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;Remove rdoc template incorporating google analytics from source control. The file just needs to exist locally and be ignored by source control. This should stop the warning showing up on e.g. &lt;a href="http://runcoderun.com/floehopper/mocha"&gt;RunCodeRun build results&lt;/a&gt;.&lt;/li&gt;
	&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/boQWys8YpIk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/09/18/mocha-release-0-9-8</feedburner:origLink></entry>
  <entry>
    <author>
      <name>James Mead</name>
    </author>
    <id>urn:uuid:4f6bf634-8f6e-44be-a5c0-76d1b3199a6a</id>
    <published>2009-09-14T16:58:56+00:00</published>
    <updated>2009-09-14T17:07:32+00:00</updated>
    <title type="html">Mocha Test Spies</title>
    <link href="http://feedproxy.google.com/~r/floehopper-blog/~3/TWROFmPw8Yo/mocha-test-spies" 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="spy" scheme="http://blog.floehopper.org/articles/tag/spy" />
    <category term="fork" scheme="http://blog.floehopper.org/articles/tag/fork" />
    <category term="thoughtbot" scheme="http://blog.floehopper.org/articles/tag/thoughtbot" />
    <summary type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;Today I finally got round to looking at &lt;a href="http://github.com/jferris/mocha/commits/spies"&gt;Joe Ferris&amp;#8217; Test Spies fork&lt;/a&gt; of Mocha. Joe explained how Test Spies work and why he thinks they are useful in &lt;a href="http://robots.thoughtbot.com/post/159805295/spy-vs-spy"&gt;Spy vs spy&lt;/a&gt; on the ThoughtBot blog. I apologise to Joe for not getting round to this sooner.&lt;/p&gt;


	&lt;p&gt;I have a number of hesitations about merging these changes into &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; as they stand. My thinking hasn&amp;#8217;t really crystallized, but in these situations I often find it&amp;#8217;s useful to force myself to try and explain myself in writing. Hopefully it&amp;#8217;ll also generate some feedback.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d like to thank Joe for taking the time to fork Mocha and add this functionality. I&amp;#8217;m particularly grateful that he&amp;#8217;s taken the trouble to write a &lt;a href="http://github.com/jferris/mocha/raw/spies/test/acceptance/spy_test.rb"&gt;bunch of high-level acceptance tests&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Concept&lt;/h3&gt;


	&lt;p&gt;In this section I&amp;#8217;ve tried to write up some comments on &lt;a href="http://robots.thoughtbot.com/post/159805295/spy-vs-spy"&gt;Joe&amp;#8217;s blog post&lt;/a&gt; under roughly the same headings :-&lt;/p&gt;


	&lt;h4&gt;Why would I let spies in my code?&lt;/h4&gt;


	&lt;p&gt;Joe correctly points out that setting up expectations before exercising the object under test is a bit of a departure from the traditional &lt;a href="http://xunitpatterns.com/Four%20Phase%20Test.html"&gt;Four-Phase Test&lt;/a&gt; regime. I can see how some people might see this as counter-intuitive, but it doesn&amp;#8217;t seem particularly so to me. Also the idea of &lt;a href="http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt; (i.e. setting up expectations before the Exercise phase) has a couple of advantages :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Using &lt;a href="http://xunitpatterns.com/Test%20Spy.html"&gt;Test Spies&lt;/a&gt;, you have to (a) set up a stub so the mock object knows what value to return and (b) assert that the stubbed method was invoked the requisite number of times with the appropriate parameters. Whereas using &lt;a href=":http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt;, these are combined into setting up an expectation on the mock object. I think this results in terser code with less duplication.&lt;/li&gt;
		&lt;li&gt;Using &lt;a href=":http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt; means that the test can fail fast if an unexpected invocation is made against a mock object. Failing fast is generally a good idea, because you are more likely to be able to identify the root cause of the problem.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;Sharing stubs in a context&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;describe&lt;/span&gt; &lt;span class="constant"&gt;PostsController&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;on GET show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;before&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:each&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="attribute"&gt;@post&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;a post&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="symbol"&gt;:to_param&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
    &lt;span class="constant"&gt;Post&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;:find&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

    &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:id&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;render_template&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;

  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should find and assign the given post&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:find&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;assign_to&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="attribute"&gt;@post&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m going to struggle a bit when commenting on this code example for a couple of reasons :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;I dislike the use of &lt;code&gt;setup&lt;/code&gt; methods (&lt;code&gt;before&lt;/code&gt; in this &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt; example). I prefer to do my &lt;a href="http://blog.jayfields.com/2007/06/testing-inline-setup.html"&gt;setup in-line in the test&lt;/a&gt; to make the test as independent and as explicit as possible. I particularly dislike exercising the object under test within the &lt;code&gt;setup&lt;/code&gt; method. To me this seems like a more fundamental breakage of the &lt;a href="http://xunitpatterns.com/Four%20Phase%20Test.html"&gt;Four-Phase Test&lt;/a&gt; concept.&lt;/li&gt;
		&lt;li&gt;In this example, I would not want to assert that &lt;code&gt;Post.find&lt;/code&gt; has been called. &lt;a href="http://www.natpryce.com/"&gt;Nat Pryce&lt;/a&gt; (one of the authors of jMock) has a rule of thumb that says: &amp;#8220;&lt;a href="http://www.jmock.org/yoga.html"&gt;stub queries and expect commands&lt;/a&gt;&amp;#8221;. In this example, the call to &lt;code&gt;Post.find&lt;/code&gt; is clearly a query, so I would just stub it. I think about it like this: (a) stubbing &lt;code&gt;Post.find&lt;/code&gt; is setting up the environment and making the instance of &lt;code&gt;Post&lt;/code&gt; available; (b) the assertion then checks that the instance of &lt;code&gt;Post&lt;/code&gt; is assigned to the &lt;code&gt;@post&lt;/code&gt; instance variable; (c) the combination of (a) and (b) is enough to tell me that the &lt;code&gt;Post.find&lt;/code&gt; method has been called &amp;#8211; where else would the controller have got the instance of &lt;code&gt;Post&lt;/code&gt; from?&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So I&amp;#8217;m not convinced I would need &lt;em&gt;Test Spies&lt;/em&gt; for this example.&lt;/p&gt;


	&lt;h4&gt;Sharing stubs between tests&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;stub_post&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{})&lt;/span&gt;
    &lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt;
      &lt;span class="symbol"&gt;:to_param&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt;
      &lt;span class="symbol"&gt;:published?&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="constant"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt;
      &lt;span class="symbol"&gt;:title&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;a title&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
    &lt;span class="punct"&gt;}.&lt;/span&gt;&lt;span class="ident"&gt;update&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;a post&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;stub_post!&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{})&lt;/span&gt;
    &lt;span class="ident"&gt;returning&lt;/span&gt; &lt;span class="ident"&gt;stub_post&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
      &lt;span class="constant"&gt;Post&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;:find&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;post&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;end&lt;/span&gt;

&lt;span class="ident"&gt;describe&lt;/span&gt; &lt;span class="constant"&gt;PostsController&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should show a published post on GET show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="ident"&gt;post&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub_post!&lt;/span&gt;
    &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:id&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;
    &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:find&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:published?&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;render_template&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;assign_to&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&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="ident"&gt;describe&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/posts/show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should display a post&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="ident"&gt;assigns&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub_post&lt;/span&gt;
    &lt;span class="ident"&gt;render&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;/posts/show&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
    &lt;span class="ident"&gt;template&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_tag&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;h1&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;assigns&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;].&lt;/span&gt;&lt;span class="ident"&gt;title&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;ul&gt;
	&lt;li&gt;In this example, as above, I would stub the call to &lt;code&gt;Post.find&lt;/code&gt; rather than expect it.&lt;/li&gt;
		&lt;li&gt;I&amp;#8217;d also prefer to use a real &lt;code&gt;Post&lt;/code&gt; instance rather than a stub object. I&amp;#8217;d use some kind of &lt;a href="http://natpryce.com/articles/000714.html"&gt;Test Data Builder&lt;/a&gt; like &lt;a href="http://github.com/thoughtbot/factory_girl"&gt;factory_girl&lt;/a&gt; to remove any duplication rather than methods like those in the &lt;code&gt;PostHelpers&lt;/code&gt; module. While these &lt;code&gt;ActiveRecord&lt;/code&gt; objects aren&amp;#8217;t strictly &lt;em&gt;Value Objects&lt;/em&gt;, I can&amp;#8217;t help but think that &lt;a href="http://markmail.org/message/v6rvuvmfygaboruf"&gt;this quote from Nat Pryce&lt;/a&gt; is relevant :-&lt;/li&gt;
	&lt;/ul&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Some languages might allow you to &lt;strong&gt;stub&lt;/strong&gt; a value, but what&amp;#8217;s the point? It is easier and less error prone to use the real type. If it&amp;#8217;s not easier to use the real type then, I think, you should investigate why. What can you do to make the value type easier to use?&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;&lt;a href="http://www.m3p.co.uk/blog/"&gt;Steve Freeman&lt;/a&gt; makes a similar point in &lt;a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html"&gt;Test Smell: Everything is mocked&lt;/a&gt;.&lt;/p&gt;


	&lt;h4&gt;Reusable matchers and assertions&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="comment"&gt;# post.class.should have_received(:find).with(post.to_param)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="comment"&gt;# Post.should have_received(:new).with(post_attrs)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;build&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="comment"&gt;# Post.should have_received(:new).with(post_attrs)&lt;/span&gt;
&lt;span class="comment"&gt;# post.should have_received(:save)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;build_and_save&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m not convinced that extracting the assertion part of an expectation is sensible, because it&amp;#8217;ll always need to be used in conjunction with the stub part of the same expectation.&lt;/p&gt;


	&lt;h3&gt;Syntax&lt;/h3&gt;


	&lt;p&gt;I think the suggested syntax extension is inconsistent with the existing Mocha &lt;span class="caps"&gt;API&lt;/span&gt; and a little clunky. See &lt;a href="http://groups.google.com/group/mocha-developer/msg/8d719b4aa729928f?hl=en"&gt;James Rosen&amp;#8217;s comment&lt;/a&gt; on the &lt;a href="http://groups.google.com/group/mocha-developer?hl=en"&gt;mailing list&lt;/a&gt;. Looking at the following examples given in the documentation :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;assert_received&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="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;{|&lt;/span&gt;&lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;
  &lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;{|&lt;/span&gt;&lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I think I&amp;#8217;d prefer to see something like :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Or something like :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Note that I haven&amp;#8217;t completely thought through the implementation implications of these suggestions i.e. whether they are even possible!&lt;/p&gt;


	&lt;h3&gt;Implementation&lt;/h3&gt;


	&lt;p&gt;The code looks good and, since Joe has written acceptance tests, there shouldn&amp;#8217;t be too much difficulty in doing a bit of refactoring. I like the idea of introducing a model for an &lt;a href="http://github.com/jferris/mocha/raw/spies/lib/mocha/invocation.rb"&gt;Invocation&lt;/a&gt; , but I think the &lt;code&gt;Invocation&lt;/code&gt; instances should be stored by the relevant &lt;code&gt;Mock&lt;/code&gt; instance rather than the &lt;code&gt;Mockery&lt;/code&gt;. Similarly I&amp;#8217;d push more of the logic in the &lt;a href="http://github.com/jferris/mocha/blob/4ba321eca2439ae5f55a611e2df716ea7af44ef4/lib/mocha/api.rb#L165"&gt;HaveReceived&lt;/a&gt; class into relevant objects. And I&amp;#8217;d like to avoid having to make &lt;code&gt;Expectation#invocation_count&lt;/code&gt; writeable.&lt;/p&gt;


	&lt;p&gt;One slight concern is what happens if someone mixes up &lt;em&gt;Expected Behaviour Specification&lt;/em&gt; expectations with &lt;em&gt;Test Spies&lt;/em&gt; stubs and assertions? I&amp;#8217;d probably at least want some acceptance tests to convince me that there are no complications on this front.&lt;/p&gt;


	&lt;h3&gt;Conclusion&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m sure that some people find the changes useful, but I&amp;#8217;m not yet convinced I want to merge the &lt;a href="http://github.com/jferris/mocha/commits/spies"&gt;Test Spies&lt;/a&gt; changes into &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;. Please feel free to try and convince me, either here in the &lt;a href="#comments"&gt;comments&lt;/a&gt; or in the &lt;a href="http://groups.google.com/group/mocha-developer/browse_thread/thread/3c3fba12cf313b12?hl=en"&gt;mailing list thread&lt;/a&gt;.&lt;/p&gt;</summary>
    <content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;


	&lt;p&gt;Today I finally got round to looking at &lt;a href="http://github.com/jferris/mocha/commits/spies"&gt;Joe Ferris&amp;#8217; Test Spies fork&lt;/a&gt; of Mocha. Joe explained how Test Spies work and why he thinks they are useful in &lt;a href="http://robots.thoughtbot.com/post/159805295/spy-vs-spy"&gt;Spy vs spy&lt;/a&gt; on the ThoughtBot blog. I apologise to Joe for not getting round to this sooner.&lt;/p&gt;


	&lt;p&gt;I have a number of hesitations about merging these changes into &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; as they stand. My thinking hasn&amp;#8217;t really crystallized, but in these situations I often find it&amp;#8217;s useful to force myself to try and explain myself in writing. Hopefully it&amp;#8217;ll also generate some feedback.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d like to thank Joe for taking the time to fork Mocha and add this functionality. I&amp;#8217;m particularly grateful that he&amp;#8217;s taken the trouble to write a &lt;a href="http://github.com/jferris/mocha/raw/spies/test/acceptance/spy_test.rb"&gt;bunch of high-level acceptance tests&lt;/a&gt;.&lt;/p&gt;


	&lt;h3&gt;Concept&lt;/h3&gt;


	&lt;p&gt;In this section I&amp;#8217;ve tried to write up some comments on &lt;a href="http://robots.thoughtbot.com/post/159805295/spy-vs-spy"&gt;Joe&amp;#8217;s blog post&lt;/a&gt; under roughly the same headings :-&lt;/p&gt;


	&lt;h4&gt;Why would I let spies in my code?&lt;/h4&gt;


	&lt;p&gt;Joe correctly points out that setting up expectations before exercising the object under test is a bit of a departure from the traditional &lt;a href="http://xunitpatterns.com/Four%20Phase%20Test.html"&gt;Four-Phase Test&lt;/a&gt; regime. I can see how some people might see this as counter-intuitive, but it doesn&amp;#8217;t seem particularly so to me. Also the idea of &lt;a href="http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt; (i.e. setting up expectations before the Exercise phase) has a couple of advantages :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Using &lt;a href="http://xunitpatterns.com/Test%20Spy.html"&gt;Test Spies&lt;/a&gt;, you have to (a) set up a stub so the mock object knows what value to return and (b) assert that the stubbed method was invoked the requisite number of times with the appropriate parameters. Whereas using &lt;a href=":http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt;, these are combined into setting up an expectation on the mock object. I think this results in terser code with less duplication.&lt;/li&gt;
		&lt;li&gt;Using &lt;a href=":http://xunitpatterns.com/Behavior%20Verification.html#Expected%20Behavior%20Specification"&gt;Expected Behaviour Specification&lt;/a&gt; means that the test can fail fast if an unexpected invocation is made against a mock object. Failing fast is generally a good idea, because you are more likely to be able to identify the root cause of the problem.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;Sharing stubs in a context&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;describe&lt;/span&gt; &lt;span class="constant"&gt;PostsController&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;on GET show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;before&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:each&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="attribute"&gt;@post&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;a post&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="symbol"&gt;:to_param&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
    &lt;span class="constant"&gt;Post&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;:find&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

    &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:id&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;render_template&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;

  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should find and assign the given post&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:find&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="attribute"&gt;@post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;assign_to&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="attribute"&gt;@post&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m going to struggle a bit when commenting on this code example for a couple of reasons :-&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;I dislike the use of &lt;code&gt;setup&lt;/code&gt; methods (&lt;code&gt;before&lt;/code&gt; in this &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt; example). I prefer to do my &lt;a href="http://blog.jayfields.com/2007/06/testing-inline-setup.html"&gt;setup in-line in the test&lt;/a&gt; to make the test as independent and as explicit as possible. I particularly dislike exercising the object under test within the &lt;code&gt;setup&lt;/code&gt; method. To me this seems like a more fundamental breakage of the &lt;a href="http://xunitpatterns.com/Four%20Phase%20Test.html"&gt;Four-Phase Test&lt;/a&gt; concept.&lt;/li&gt;
		&lt;li&gt;In this example, I would not want to assert that &lt;code&gt;Post.find&lt;/code&gt; has been called. &lt;a href="http://www.natpryce.com/"&gt;Nat Pryce&lt;/a&gt; (one of the authors of jMock) has a rule of thumb that says: &amp;#8220;&lt;a href="http://www.jmock.org/yoga.html"&gt;stub queries and expect commands&lt;/a&gt;&amp;#8221;. In this example, the call to &lt;code&gt;Post.find&lt;/code&gt; is clearly a query, so I would just stub it. I think about it like this: (a) stubbing &lt;code&gt;Post.find&lt;/code&gt; is setting up the environment and making the instance of &lt;code&gt;Post&lt;/code&gt; available; (b) the assertion then checks that the instance of &lt;code&gt;Post&lt;/code&gt; is assigned to the &lt;code&gt;@post&lt;/code&gt; instance variable; (c) the combination of (a) and (b) is enough to tell me that the &lt;code&gt;Post.find&lt;/code&gt; method has been called &amp;#8211; where else would the controller have got the instance of &lt;code&gt;Post&lt;/code&gt; from?&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So I&amp;#8217;m not convinced I would need &lt;em&gt;Test Spies&lt;/em&gt; for this example.&lt;/p&gt;


	&lt;h4&gt;Sharing stubs between tests&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;stub_post&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{})&lt;/span&gt;
    &lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt;
      &lt;span class="symbol"&gt;:to_param&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt;
      &lt;span class="symbol"&gt;:published?&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="constant"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt;
      &lt;span class="symbol"&gt;:title&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;a title&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
    &lt;span class="punct"&gt;}.&lt;/span&gt;&lt;span class="ident"&gt;update&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;stub&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;a post&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;stub_post!&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post_attrs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{})&lt;/span&gt;
    &lt;span class="ident"&gt;returning&lt;/span&gt; &lt;span class="ident"&gt;stub_post&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
      &lt;span class="constant"&gt;Post&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;:find&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;post&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;end&lt;/span&gt;

&lt;span class="ident"&gt;describe&lt;/span&gt; &lt;span class="constant"&gt;PostsController&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should show a published post on GET show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="ident"&gt;post&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub_post!&lt;/span&gt;
    &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:id&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;
    &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:find&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_param&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:published?&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;render_template&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:show&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;assign_to&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&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="ident"&gt;describe&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;/posts/show&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;include&lt;/span&gt; &lt;span class="constant"&gt;PostHelpers&lt;/span&gt;
  &lt;span class="ident"&gt;it&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;should display a post&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="ident"&gt;assigns&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;stub_post&lt;/span&gt;
    &lt;span class="ident"&gt;render&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;/posts/show&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
    &lt;span class="ident"&gt;template&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;have_tag&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;h1&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;assigns&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;].&lt;/span&gt;&lt;span class="ident"&gt;title&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;ul&gt;
	&lt;li&gt;In this example, as above, I would stub the call to &lt;code&gt;Post.find&lt;/code&gt; rather than expect it.&lt;/li&gt;
		&lt;li&gt;I&amp;#8217;d also prefer to use a real &lt;code&gt;Post&lt;/code&gt; instance rather than a stub object. I&amp;#8217;d use some kind of &lt;a href="http://natpryce.com/articles/000714.html"&gt;Test Data Builder&lt;/a&gt; like &lt;a href="http://github.com/thoughtbot/factory_girl"&gt;factory_girl&lt;/a&gt; to remove any duplication rather than methods like those in the &lt;code&gt;PostHelpers&lt;/code&gt; module. While these &lt;code&gt;ActiveRecord&lt;/code&gt; objects aren&amp;#8217;t strictly &lt;em&gt;Value Objects&lt;/em&gt;, I can&amp;#8217;t help but think that &lt;a href="http://markmail.org/message/v6rvuvmfygaboruf"&gt;this quote from Nat Pryce&lt;/a&gt; is relevant :-&lt;/li&gt;
	&lt;/ul&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Some languages might allow you to &lt;strong&gt;stub&lt;/strong&gt; a value, but what&amp;#8217;s the point? It is easier and less error prone to use the real type. If it&amp;#8217;s not easier to use the real type then, I think, you should investigate why. What can you do to make the value type easier to use?&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;&lt;a href="http://www.m3p.co.uk/blog/"&gt;Steve Freeman&lt;/a&gt; makes a similar point in &lt;a href="http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html"&gt;Test Smell: Everything is mocked&lt;/a&gt;.&lt;/p&gt;


	&lt;h4&gt;Reusable matchers and assertions&lt;/h4&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="comment"&gt;# post.class.should have_received(:find).with(post.to_param)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;post&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="comment"&gt;# Post.should have_received(:new).with(post_attrs)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;build&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="comment"&gt;# Post.should have_received(:new).with(post_attrs)&lt;/span&gt;
&lt;span class="comment"&gt;# post.should have_received(:save)&lt;/span&gt;
&lt;span class="ident"&gt;should&lt;/span&gt; &lt;span class="ident"&gt;build_and_save&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;post_attrs&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m not convinced that extracting the assertion part of an expectation is sensible, because it&amp;#8217;ll always need to be used in conjunction with the stub part of the same expectation.&lt;/p&gt;


	&lt;h3&gt;Syntax&lt;/h3&gt;


	&lt;p&gt;I think the suggested syntax extension is inconsistent with the existing Mocha &lt;span class="caps"&gt;API&lt;/span&gt; and a little clunky. See &lt;a href="http://groups.google.com/group/mocha-developer/msg/8d719b4aa729928f?hl=en"&gt;James Rosen&amp;#8217;s comment&lt;/a&gt; on the &lt;a href="http://groups.google.com/group/mocha-developer?hl=en"&gt;mailing list&lt;/a&gt;. Looking at the following examples given in the documentation :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;assert_received&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="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;{|&lt;/span&gt;&lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;
  &lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="punct"&gt;{|&lt;/span&gt;&lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;expect&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I think I&amp;#8217;d prefer to see something like :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;assert_that&lt;/span&gt; &lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Or something like :-&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;mock&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:to_s&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="constant"&gt;Radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:new&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;1041&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;radio&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;assert_received&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:volume&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;11&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;twice&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Note that I haven&amp;#8217;t completely thought through the implementation implications of these suggestions i.e. whether they are even possible!&lt;/p&gt;


	&lt;h3&gt;Implementation&lt;/h3&gt;


	&lt;p&gt;The code looks good and, since Joe has written acceptance tests, there shouldn&amp;#8217;t be too much difficulty in doing a bit of refactoring. I like the idea of introducing a model for an &lt;a href="http://github.com/jferris/mocha/raw/spies/lib/mocha/invocation.rb"&gt;Invocation&lt;/a&gt; , but I think the &lt;code&gt;Invocation&lt;/code&gt; instances should be stored by the relevant &lt;code&gt;Mock&lt;/code&gt; instance rather than the &lt;code&gt;Mockery&lt;/code&gt;. Similarly I&amp;#8217;d push more of the logic in the &lt;a href="http://github.com/jferris/mocha/blob/4ba321eca2439ae5f55a611e2df716ea7af44ef4/lib/mocha/api.rb#L165"&gt;HaveReceived&lt;/a&gt; class into relevant objects. And I&amp;#8217;d like to avoid having to make &lt;code&gt;Expectation#invocation_count&lt;/code&gt; writeable.&lt;/p&gt;


	&lt;p&gt;One slight concern is what happens if someone mixes up &lt;em&gt;Expected Behaviour Specification&lt;/em&gt; expectations with &lt;em&gt;Test Spies&lt;/em&gt; stubs and assertions? I&amp;#8217;d probably at least want some acceptance tests to convince me that there are no complications on this front.&lt;/p&gt;


	&lt;h3&gt;Conclusion&lt;/h3&gt;


	&lt;p&gt;I&amp;#8217;m sure that some people find the changes useful, but I&amp;#8217;m not yet convinced I want to merge the &lt;a href="http://github.com/jferris/mocha/commits/spies"&gt;Test Spies&lt;/a&gt; changes into &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt;. Please feel free to try and convince me, either here in the &lt;a href="#comments"&gt;comments&lt;/a&gt; or in the &lt;a href="http://groups.google.com/group/mocha-developer/browse_thread/thread/3c3fba12cf313b12?hl=en"&gt;mailing list thread&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/floehopper-blog/~4/TWROFmPw8Yo" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://blog.floehopper.org/articles/2009/09/14/mocha-test-spies</feedburner:origLink></entry>
  <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://feedproxy.google.com/~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://feedproxy.google.com/~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://feedproxy.google.com/~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://feedproxy.google.com/~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://feedproxy.google.com/~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://feedproxy.google.com/~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>
</feed>
