<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Not in code &#187; testing</title>
	<atom:link href="http://notincode.wordpress.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://notincode.wordpress.com</link>
	<description>Software is about people</description>
	<lastBuildDate>Mon, 22 Jun 2009 00:33:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='notincode.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/1bb58d250bfeaaf97c6daf48b9a54b30?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Not in code &#187; testing</title>
		<link>http://notincode.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://notincode.wordpress.com/osd.xml" title="Not in code" />
	<atom:link rel='hub' href='http://notincode.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Testing instance methods in a Module with Object.extend()</title>
		<link>http://notincode.wordpress.com/2008/06/07/testing-instance-methods-in-a-module-with-objectextend/</link>
		<comments>http://notincode.wordpress.com/2008/06/07/testing-instance-methods-in-a-module-with-objectextend/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 17:15:19 +0000</pubDate>
		<dc:creator>hiremaga</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://notincode.wordpress.com/?p=228</guid>
		<description><![CDATA[A common type of mixin I&#8217;ve encountered involves a Module with instance methods which is included into a Class. Writing an orthogonal test for a target Class is easy enough, you simply mock/stub any methods the Module provides. Testing the Module elegantly however is less obvious, atleast it wasn&#8217;t obvious to me. One approach I&#8217;ve [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=228&subd=notincode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>A common type of mixin I&#8217;ve encountered involves a Module with instance methods which is <a href="http://www.ruby-doc.org/core/classes/Module.html#M001661">included</a> into a Class.</p>
<p>Writing an orthogonal test for a target Class is easy enough, you simply mock/stub any methods the Module provides. </p>
<p>Testing the Module elegantly however is less obvious, atleast it wasn&#8217;t obvious to me.</p>
<p>One approach I&#8217;ve used is to create a fake class for the test, include the Module and finally instantiate this for the test. But there&#8217;s the issue of testing the Module&#8217;s interaction with the including Class. For this you could partially mock/stub the test class instance, but there&#8217;s a simpler approach that avoids the test class altogether: create an ordinary rSpec mock instance and <a href="http://www.ruby-doc.org/core/classes/Object.html#M000337">extend</a> it with the Module.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notincode.wordpress.com/228/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notincode.wordpress.com/228/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notincode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notincode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notincode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notincode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notincode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notincode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notincode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notincode.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notincode.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notincode.wordpress.com/228/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=228&subd=notincode&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://notincode.wordpress.com/2008/06/07/testing-instance-methods-in-a-module-with-objectextend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd84e3662c2772ec1f22649b9aa7464a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hiremaga</media:title>
		</media:content>
	</item>
		<item>
		<title>Why I test, and why do you test?</title>
		<link>http://notincode.wordpress.com/2008/02/07/why-i-test-and-why-do-you-test/</link>
		<comments>http://notincode.wordpress.com/2008/02/07/why-i-test-and-why-do-you-test/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 10:42:12 +0000</pubDate>
		<dc:creator>hiremaga</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://notincode.wordpress.com/?p=226</guid>
		<description><![CDATA[This is most of an email I sent to an internal Cogent mailing list after an entertaining exchange between a couple of the guys about testing styles/philosophies. Craig suggested I post it here, so here &#8217;tis :) &#8211; snip &#8211; First about unit and integration tests. I write unit tests for focused feedback; i.e. tell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=226&subd=notincode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>This is most of an email I sent to an internal <a href="http://www.cogentconsulting.com.au" target="_blank">Cogent</a> mailing list after an entertaining exchange between a couple of the guys about testing styles/philosophies. <a href="http://www.craigambrose.com/" target="_blank">Craig</a> suggested I post it here, so here &#8217;tis :)</p>
<p>&#8211; snip &#8211;</p>
<p>First about unit and integration tests.</p>
<ul>
<li>I write <b>unit tests</b> for <b>focused feedback</b>; i.e. tell me exactly what broke. To keep them focused I try to keep them orthogonal which usually means using fakes of any collaborators.</li>
<li>I write <b>integration tests</b> where I need more <b>safety</b> than a unit test will offer. They seem even more important when I&#8217;m stubbing and mocking a lot in a dynamically typed language like Ruby.</li>
<li>I write <b>both</b> types of tests to help <b>convey intent</b> and <b>understand the problem</b> better. I TDD with either a unit test or integration test, whichever feels natural.</li>
</ul>
<p>Then about <a href="http://martinfowler.com/articles/mocksArentStubs.html" target="_blank">interaction and state based testing</a>.</p>
<ul>
<li>I pick the approach that feels natural at the time, favouring neither by default. I struggle with rules about when to use which.</li>
<li>I dislike interaction tests that look suspiciously similar/symmetrical/coupled to the code they refer to. I expect a test to earn its right to exist, and therefore add to the size of the codebase and build&#8217;s time, by either conveying intent that is difficult to express in the code itself (which is why I love the term &#8216;<a href="http://rspec.info/examples.html" target="_blank">example</a>&#8216;) or addressing some other consciously identified risk.</li>
</ul>
<p>Your thoughts?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notincode.wordpress.com/226/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notincode.wordpress.com/226/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notincode.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notincode.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notincode.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notincode.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notincode.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notincode.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notincode.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notincode.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notincode.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notincode.wordpress.com/226/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=226&subd=notincode&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://notincode.wordpress.com/2008/02/07/why-i-test-and-why-do-you-test/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd84e3662c2772ec1f22649b9aa7464a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hiremaga</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t get forked by rSpec</title>
		<link>http://notincode.wordpress.com/2008/01/31/dont-get-forked-by-rspec/</link>
		<comments>http://notincode.wordpress.com/2008/01/31/dont-get-forked-by-rspec/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 12:24:12 +0000</pubDate>
		<dc:creator>hiremaga</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://notincode.wordpress.com/?p=225</guid>
		<description><![CDATA[A 2 week break over christmas/new years and pairing with the incandescent Mark Ryall seemed to make our unit test (spec?) suite time of 200 seconds feel excruciatingly slow. I&#8217;m only kidding Mark, I really do enjoy pairing with you. :) (How do you punctuate around a smiley?) Feeling even more (irrationally) intolerant than usual, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=225&subd=notincode&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>A 2 week break over christmas/new years and pairing with the incandescent Mark Ryall seemed to make our unit test (spec?) suite time of 200 seconds feel excruciatingly slow. I&#8217;m only kidding Mark, I really do enjoy pairing with you. :)</p>
<p>(How do you punctuate around a smiley?)</p>
<p>Feeling even more (irrationally) intolerant than usual, I convinced Mark to let us switch away from the reams of text produced by rSpec&#8217;s &#8216;specdoc&#8217; format to its more succinct &#8216;progress&#8217; format and we immediately noticed something odd. Each example was being run 7 times, in fact the entire suite was being run several times with runs interleaved!</p>
<p>Some perplexed investigation and educated guessing finally revealed the cause.</p>
<p>While rSpec gives you a SpecRunner for free via an at_exit hook, we use a script to explicitly invoke a CommandLine::SpecRunner. This is in part because our project is built by Ant (it&#8217;s a polygot-project; a mishmash of Java, Ruby, Python and, somewhat unfortunately IMO, Bash) and in part just because &#8230;</p>
<p>rSpec&#8217;s at_exit hook allows you to run your specs directly via the ruby command (e.g. $ ruby three_is_greater_than_four_spec.rb) and is responsible enough to ensure you haven&#8217;t already run these specs with a custom runner. Except if you call Process.fork during an example.</p>
<p>When you fork in an example the at_exit hook gets replicated in the child process and when this child process tries to exit, you guessed it, it runs your specs. Turns out we had quite a few unstubbed forks in our unit level specs. The immediate remedy was to stub these; they are unit level specs which should after all  be orthogonal.</p>
<p>To make sure we aren&#8217;t inadvertently bitten again we&#8217;ve intercepted rSpec&#8217;s at_exit hook from any child processes by creating our own at_exit hook which exits without executing any other at_exit blocks, i.e. :at_exit { exit! }</p>
<p>Our 830ish specs now run in 15 seconds. The numbers don&#8217;t quite add up (200 seconds / 7 processes &gt; 15 seconds), but since I&#8217;m certain none are being skipped,  I&#8217;m content with this outcome.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/notincode.wordpress.com/225/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/notincode.wordpress.com/225/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/notincode.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/notincode.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/notincode.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/notincode.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/notincode.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/notincode.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/notincode.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/notincode.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/notincode.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/notincode.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.hiremaga.com&blog=2620597&post=225&subd=notincode&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://notincode.wordpress.com/2008/01/31/dont-get-forked-by-rspec/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd84e3662c2772ec1f22649b9aa7464a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hiremaga</media:title>
		</media:content>
	</item>
	</channel>
</rss>