<?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/"
	>

<channel>
	<title>Muziboo Development Blog &#187; testing</title>
	<atom:link href="http://devblog.muziboo.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.muziboo.com</link>
	<description>Muziboo development stories. Mostly set in ruby land</description>
	<lastBuildDate>Fri, 01 Apr 2011 04:52:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pickle (Cucumber) steps for verifying counter cache</title>
		<link>http://devblog.muziboo.com/2010/06/17/pickle-cucumber-steps-for-verifying-counter-cache/</link>
		<comments>http://devblog.muziboo.com/2010/06/17/pickle-cucumber-steps-for-verifying-counter-cache/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 11:39:03 +0000</pubDate>
		<dc:creator>prateek</dc:creator>
				<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://devblog.muziboo.com/?p=94</guid>
		<description><![CDATA[
			
				
			
		
Pickle is a great add on to cucumber as it provides steps for often used scenario. There is a step provided for verifying the association size of an active record instance. Therefore you can write something like
Then the user: &#8220;Joe&#8221; should have 1 friends
and it will check if joe.friends.size == 0. However this does not [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdevblog.muziboo.com%2F2010%2F06%2F17%2Fpickle-cucumber-steps-for-verifying-counter-cache%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdevblog.muziboo.com%2F2010%2F06%2F17%2Fpickle-cucumber-steps-for-verifying-counter-cache%2F&amp;source=muziboo&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://github.com/ianwhite/pickle" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">Pickle</a> is a great add on to cucumber as it provides steps for often used scenario. There is a step provided for verifying the association size of an active record instance. Therefore you can write something like</p>
<p>Then the user: &#8220;Joe&#8221; should have 1 friends</p>
<p>and it will check if joe.friends.size == 0. However this does not check the counter cache (if you have one). I modified it a bit to verify counter cache (changes in file features/step_definitions/pickle_steps.rb)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># assert size of association</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;">#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>model!<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{association}_count&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    model!<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{association}_count&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> == size.<span style="color:#9900CC;">to_i</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    model!<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>association<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">size</span>.<span style="color:#9900CC;">should</span> == size.<span style="color:#9900CC;">to_i</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This assumes that you counter cache is named association_cache which is the convention in rails&#8217; world.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.muziboo.com/2010/06/17/pickle-cucumber-steps-for-verifying-counter-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

