<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:ent="http://www.purl.org/NET/ENT/1.0/" version="2.0">
  <channel>
    <title>Curiouser and Curiouser! on spec-first</title>
    <link>http://matt.blogs.it/</link>
    <description>RSS feed for topic spec-first</description>
    <copyright>Copyright 2008 Matt Mower. Some rights reserved.</copyright>
    <generator>Squib/0.5.0.382</generator>
    <managingEditor>self@mattmower.com</managingEditor>
    <webMaster>self@mattmower.com</webMaster>
    <language>en-gb</language>
    <item>
      <title>Bring out your Mocks</title>
      <link>http://matt.blogs.it/entries/00002913.html</link>
      <pubDate>Tue, 16 Sep 2008 19:23:17 +0100</pubDate>
      <description>&lt;p&gt;I wrote &lt;a href="http://matt.blogs.it/entries/00002905.html"&gt;last week&lt;/a&gt; about ObjectDaddy, a plugin to enhance your specs, by Rick Bradley and Yossef Mendelssohn. For my money &lt;a href="http://github.com/flogic/object_daddy/tree/master"&gt;ObjectDaddy&lt;/a&gt; is well worth checking out.&lt;/p&gt;

&lt;p&gt;Anyone who has used fixtures knows the pain that comes with a growing tangle of unkempt fixtures that nobody can figure out or use leading them to add new ones for each test, making it harder to figure them out, and so on.&lt;/p&gt;

&lt;p&gt;Faced with that nightmare mocks seem like a panacea. No more fixtures! A rousing Huzzah! is heard all around. But, after the dust has settled, you start wondering what you've bought.&lt;/p&gt;

&lt;p&gt;My experience is that they're not much use when testing models, and in my controller specs, in order to jimmy the right mock into position for the expectation, I often ended up with a series of nested mocks that were often, conceptually, more hideous than the fixtures they had replaced.&lt;/p&gt;

&lt;p&gt;Now Sometimes this pointed to a fat controller desperately in need of the number of it's local Weight Watchers meeting so it wasn't all bad. But quite often it felt cumbersome and artificial.&lt;/p&gt;

&lt;p&gt;ObjectDaddy, for me, has been win-win. Being able to write:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;u1, u2 = User.generate, User.generate
r = u2.add_contact( u1 )
put :tags, :user_id =&amp;gt; u2.login, :id =&amp;gt; u1.login, :friend =&amp;gt; 't'
u2.should have_friend( u1 )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;as if &lt;code&gt;u1&lt;/code&gt; and &lt;code&gt;u2&lt;/code&gt; were fixtures makes my specs simple and logical again. No mocks and no requirement to stub stuff. Yet those are valid &lt;code&gt;User&lt;/code&gt; objects with useful attributes generated by ObjectDaddy itself and, in some cases, exemplars (net work required there was about 5 minutes). Things like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;generator_for :email, :start =&amp;gt; 'test@domain.com' do |prev|
  user, domain = prev.split('@')
  user.succ + '@' + domain
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No maintenance, no fuss, and I know that real User objects are being pushed through the system.&lt;/p&gt;

&lt;p&gt;It makes me happy to spec again.&lt;/p&gt;</description>
      <guid isPermaLink="true">http://matt.blogs.it/entries/00002913.html</guid>
      <ent:cloud ent:href="http://matt.blogs.it/topics/">
      </ent:cloud>
    </item>
  </channel>
</rss>
