<?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 rspec</title>
    <link>http://matt.blogs.it/</link>
    <description>RSS feed for topic rspec</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>Motivation or Problem</title>
      <link>http://matt.blogs.it/entries/00002852.html</link>
      <pubDate>Fri, 23 May 2008 11:30:59 +0100</pubDate>
      <description>&lt;p&gt;Okay so I'm pleased to say that &lt;a href="http://alanbradburne.com/"&gt;Alan Bradburne&lt;/a&gt; is helping out at &lt;a href="http://reeplay.it/"&gt;Reeplay.it&lt;/a&gt; as we get ready to launch. I worked with Alan for all too brief a time while I was at &lt;a href="http://www.cominded.com/"&gt;Cominded&lt;/a&gt; but, due to the setup there, we never really had much opportunity to interact.&lt;/p&gt;

&lt;p&gt;A few months ago, since we live pretty close to each other, we started hanging out at the &lt;a href="http://www.risc.org.uk/global/"&gt;Global Cafe in Reading&lt;/a&gt; on Wednesday afternoons. We both work from home which can be a little isolating so it was nice to be out and have someone else to work with. When I needed help with reeplay.it Alan was an obvious choice and, fortunately, he was able to fit us in with his other gigs.&lt;/p&gt;

&lt;p&gt;It didn't take Alan long to realize what I was already quite uncomfortable about. The application I had written was suffering for &lt;em&gt;lonedeveloperitis&lt;/em&gt; which is that peculiar disease that can affect a code base where the developer didn't have other people to chat things over with. I made a number of decisions, largely because I had to, that I later came to regret. The most serious of those was not paying sufficient attention to testing, especially of controllers.&lt;/p&gt;

&lt;p&gt;That is not to say that nothing was tested. Far from it, I had tests for quite a lot of the functionality. Unfortunately Test::Unit doesn't give you much encouragement in how you structure your tests and I had reached the point where the tests were more a hindrance than a help in changing functionality. Sure I could check what breaks but they didn't &lt;em&gt;guide me&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;One of the first decisions we made together was to switch to RSpec. I think we both believe that the extra semantic guidance involved in RSpecs nestable &lt;code&gt;describe&lt;/code&gt; is valuable since it offers so much more context allowing you to group together related specs. Also the shared behaviours, though I'm still getting my head around how to use them, suggest that this facility runs deep.&lt;/p&gt;

&lt;p&gt;Watching Topfunky's &lt;a href="http://peepcode.com/products/rspec-basics"&gt;RSpec basics&lt;/a&gt; and &lt;a href="http://peepcode.com/products/rspec-controllers-and-tools"&gt;RSpec controllers and tools&lt;/a&gt; peepecode movies has helped a lot with getting acquianted with RSpec. One thing that comes across loudly is "Use mocks not fixtures" which, having gone through the pain of maintaining fixtures, seems like a blessing.&lt;/p&gt;

&lt;p&gt;Although I've used &lt;a href="http://mocha.rubyforge.org/"&gt;Mocha&lt;/a&gt; quite a bit I decided we would go with RSpec's built in mock framework to make it easier to re-use the tutorials (also if I had trouble converting mock_model to work properly under Mocha). We've been going along good converting tests to specs and I think the resulting specs &lt;strong&gt;are&lt;/strong&gt; clearer and better guides to the code.&lt;/p&gt;

&lt;p&gt;However it's not all roses. Today I have spent 2 hours trying to &lt;a href="http://pastie.org/202109"&gt;write a spec for a controller action&lt;/a&gt; and it's been pain all the way. The issue was setting up all of the mocks, and related mocks, and related mocks to satisfy the operations the controller invokes. My inexperience probably makes this harder but it was a lot of trial and error.&lt;/p&gt;

&lt;p&gt;I can look at this in two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using mocks &amp;amp; stubs for anything but the simplest case makes you long for the pain of maintaining fixtures, mock &amp;amp; stubs suck&lt;/li&gt;
&lt;li&gt;Using mocks &amp;amp; stubs for anything but the simplest case makes you long for the pain of maintaining fixtures, so &lt;strong&gt;keep things simple stupid&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It would be useful to know whether my &lt;a href="http://pastie.org/202109"&gt;unpleasant spec&lt;/a&gt; could be improved on it's own merits.. am I using RSpec's resources properly? I've not enough experience to judge.&lt;/p&gt;

&lt;p&gt;As a motivation to keep things simple I can understand their value. It's just that it's very hard when you want to refactor something unpleasant (and in this case the controller clearly has wayyy too much responsibility) that you have to go through the pain of speccing the existing behaviour before you can actually change it.&lt;/p&gt;

&lt;p&gt;I suppose this is the sharp end of behavioural modification :)&lt;/p&gt;</description>
      <guid isPermaLink="true">http://matt.blogs.it/entries/00002852.html</guid>
      <ent:cloud ent:href="http://matt.blogs.it/topics/">
      </ent:cloud>
    </item>
  </channel>
</rss>
