Just A Summary : Tag tdd, everything about tdd http://www.bofh.org.uk/articles/tag/tdd.rss en-us 40 Piers Cawley Practices Punditry Baby's first screencast <p>If you follow the Ruby blogs, you will probably have seen a bunch of programmers attempting to do something akin to Haskell&#8217;s <code>maybe</code>, or the ObjectiveC style, message eating null.</p> <p>Generally, by about the 3rd time you&#8217;ve written</p> <div class="typocode"><pre><code class="typocode_default ">if foo.nil? ? nil : foo.bar ... end</code></pre></div> <p>you&#8217;re getting pretty tired of it. Especially when <code>foo</code> is a variable you&#8217;ve had to introduce solely to hold a value while you check that it&#8217;s not nil. The pain really kicks in when you really want to call <code>foo.bar.baz</code>. You can end up writing monstrosities like <code>(tmp = foo.nil? ? nil : foo.bar).nil? ? nil : tmp.baz</code> (actually, if you were to write that in production code, you probably have bigger problems). One option is to just define <code>NilClass#method_missing</code> to behave like its Objective C equivalent, but I&#8217;ve never quite had the nerve to find out how that might work. I wanted to write</p> <div class="typocode"><pre><code class="typocode_default ">if maybe { foo.bar.baz } ... end</code></pre></div> <p>and have nil behave like an Objective C nil for the duration of the block, but no longer. So I wrote it. Then I thought about how to present it. I wrote the thing test first using rspec and the whole thing just flowed, but writing up a test first development process for a blog entry is painful, so I&#8217;ve made a very rough (but blessedly short) screencast of the process instead.</p> <p><a href="http://www.archive.org/download/RubyMaybeRoughcut/Monad2.mov"><img src="http://www.bofh.org.uk/images/monadcast.jpg" alt="" /></a></p> <p>That&#8217;s a slightly reduced thumbnail, the movie is substantially more readable. The bottom pane of the window is the output of autotest rerunning the spec every time either the spec or the implementation changes. The top pane alternates between the specs and the implementation. Generally, every time I edit the specs, a test starts failing and every time I edit the implementation it starts passing again. In the (any) real coding run, there were of course false starts, but generally the specs kept me pretty straight.</p> <p>A word or two of warning: This is a completely unedited, silent, screen cast, there are typos, backtrackings and other embarrassments. I stopped recording once I&#8217;d got 4 tests passing, but this is far from release quality (it&#8217;s perfectly usable if you know its limitations, but it&#8217;s not entirely robust).</p> <p>Please let me know what you think of this. I&#8217;m aiming to make a more polished version, complete with voice over and it would be good to know which bits are confusing and need addressing in more detail in the voice over.</p> Fri, 14 Mar 2008 14:29:00 -0500 urn:uuid:4b5ad7c3-d601-487b-9554-2d140f18b1a8 pdcawley@bofh.org.uk (Piers Cawley) http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comments Ruby screencast maybe rspec TDD http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast Other viewpoints, and why they are important <p>Many thanks to Paul Ingles who has just written a <a href="http://www.oobaloo.co.uk/articles/2006/08/15/writing-a-typo-sidebar-test-first-in-rails">fantastic article</a> about writing a Typo sidebar in a test driven way.</p> <p>For too long we&#8217;ve been assuming that Typo sidebars are, in fact, detestable (&#8220;If it&#8217;s not testable, it&#8217;s detestable&#8221; &#8211; someone at the Sydney XP group, by way of <a href="http://www.martinfowler.com/bliki/Detestable.html">Martin Fowler</a>). Paul neatly demonstrates that sidebars are perfectly testable, we just haven&#8217;t been testing them. Bad us.</p> <p>So, I&#8217;m rolling back the changes in my current sidebar rejig and starting again by writing some tests for a few of the core sidebars, and then I can start my refactoring without quite so much of The Fear.</p> <p>So, once again, thanks Paul. It&#8217;s really great to occasionally see the curious outsider&#8217;s view of what we&#8217;re working on &#8211; it makes us question our assumptions and often shows us better ways.</p> Wed, 16 Aug 2006 02:50:00 -0500 urn:uuid:f2098926-bad2-4a90-8f89-2ea12d300044 pdcawley@bofh.org.uk (Piers Cawley) http://www.bofh.org.uk/articles/2006/08/16/other-viewpoints-and-why-they-are-important#comments The Practice of Programming Ruby Typo testdriven TDD ruby typo sidebar http://www.bofh.org.uk/trackbacks?article_id=other-viewpoints-and-why-they-are-important&day=16&month=08&year=2006 http://www.bofh.org.uk/articles/2006/08/16/other-viewpoints-and-why-they-are-important If you test it, I will patch <p>I&#8217;ve been working on <a href="http://www.typosphere.org/">Typo</a> this weekend, mostly going through <a href="http://www.typosphere.org/trac/report/1">open tickets</a> and deciding whether to apply patches.</p> <p>There&#8217;s plenty of potentially good patches in the queue, but too many of them give me The Fear.</p> <p>They don&#8217;t have tests!</p> <p>I&#8217;m the first to admit that I&#8217;ve added untested code to my projects (and I&#8217;ve been bitten by it too), but I&#8217;m more sanguine about that risk because, when it goes wrong, I can often rack my brains and pull back some memory of what my intent was. Knowing my intent helps me write meaningful tests and fix the issue. However, I can&#8217;t remember the intent of <em>your</em> code. The only thing I have to go on is what you wrote. If you&#8217;ve written tests, I can tell what you expect your code to do, which is far more important than being able to divine what your code actually does. Given a choice between code without tests and tests without code, I&#8217;ll take the tests every time.</p> <p>So, if you&#8217;ve got a typo patch on the trac and you want it to get accepted, you <em>must</em> write tests for it. If you&#8217;re implementing something that&#8217;s supposed to be conforming to a standard, then please reference those standards in your tests.</p> Sun, 12 Mar 2006 13:17:00 -0600 urn:uuid:6024f5e6-e2e2-425f-b904-ebdd70ae9a52 pdcawley@bofh.org.uk (Piers Cawley) http://www.bofh.org.uk/articles/2006/03/12/if-you-test-it-i-will-patch#comments The Practice of Programming Ruby Typo ruby TDD testdrivendevelopment typo http://www.bofh.org.uk/trackbacks?article_id=if-you-test-it-i-will-patch&day=12&month=03&year=2006 http://www.bofh.org.uk/articles/2006/03/12/if-you-test-it-i-will-patch