<?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>Ruby Flare &#187; Testing</title>
	<atom:link href="http://rubyflare.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubyflare.com</link>
	<description></description>
	<lastBuildDate>Sat, 03 Dec 2011 14:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rubyflare.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ruby Flare &#187; Testing</title>
		<link>http://rubyflare.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rubyflare.com/osd.xml" title="Ruby Flare" />
	<atom:link rel='hub' href='http://rubyflare.com/?pushpress=hub'/>
		<item>
		<title>Test Business Behaviour, Don&#8217;t Rely on UI</title>
		<link>http://rubyflare.com/2011/01/26/test-business-behaviour-dont-rely-on-ui/</link>
		<comments>http://rubyflare.com/2011/01/26/test-business-behaviour-dont-rely-on-ui/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 14:15:37 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=261</guid>
		<description><![CDATA[I often see Cucumber features written like this: It works and does the job but I feel that it isn&#8217;t enough. It&#8217;s fragile in several ways. First, if any of your form field or button labels change or your flash message changes, you&#8217;ll need to update your feature even though the behaviour hasn&#8217;t actually changed! [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=261&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I often see Cucumber features written like this:</p>
<p><pre class="brush: plain; light: true;">
Given I a have an account with email: &quot;user@test.com&quot; and password: &quot;password&quot;
When I go to the log in page
And I fill in &quot;Email&quot; with &quot;user@test.com&quot;
And I fill in &quot;Password&quot; with &quot;password&quot;
And I press &quot;Log in&quot;
Then I should see &quot;Logged in successfully.&quot;
And I should not see &quot;Log in&quot;
</pre></p>
<p>It works and does the job but I feel that it isn&#8217;t enough. It&#8217;s fragile in several ways.<br />
<span id="more-261"></span><br />
First, if any of your form field or button labels change or your flash message changes, you&#8217;ll need to update your feature even though the behaviour hasn&#8217;t actually changed! I totally understand why we write features like this &#8211; it&#8217;s convenient, it&#8217;s quick and easy.</p>
<p>Second, have we actually verified that the user has logged in? All we&#8217;ve really done is verify that we see a particular flash message and that we no longer see a piece of text on the page. We haven&#8217;t actually verified the behaviour under test here. Again, it&#8217;s convenience but it&#8217;s one that can cause you trouble.</p>
<p>I&#8217;ve had a feature like the above where the flash text I was looking for actually appeared in a login error message. For example:</p>
<p><pre class="brush: plain; light: true;">
Then I should see &quot;successfully logged in&quot;
</pre></p>
<p>My success flash message was &#8220;#{user.name} successfully logged in&#8221; and my feature passed. But it was a false positive. In fact the user had not successfully logged in at all. My error message was &#8220;#{user.name} was not successfully logged in&#8221; so when the login failed my step would still pass because the string is found on the page.</p>
<p>Okay, that&#8217;s easy to fix but it showed me just how easy it is for a feature to be fragile and too dependent on content and UI elements. Any rearrangement or inclusion of new content on a page can have a dramatic effect on your cucumber features. Worst case scenario is that you actually break functionality but your tests return a false positive.</p>
<p>To take it a step further, what if you had only implemented the flash handling and not the actual logging in of the user yet. You would get a passing feature.</p>
<p>My point is that the verification is not strong enough. You are reliant on an artefact of the logging in process. And this artefact is not part of the business rule.</p>
<p>The business rule here is that when a user logs in with the correct credentials they are successfully logged in. It is ancillary whether they see a flash message telling them they are logged in or if they can&#8217;t see the login button anymore. What you need to check is that the user is actually logged in.</p>
<p>So replace the last two lines in the example with:</p>
<p><pre class="brush: plain; light: true;">
Then I should be logged in
And I should be on the dashboard page
</pre></p>
<p>In your step definition you should use the logic that your system uses (or will use) to check if a user is logged in. For example:</p>
<p><pre class="brush: plain; light: true;">
Then /^I should be logged in$/ do
  # get your user first
  user.should be_logged_in
end</pre></p>
<p>To take it further, you can remove the other content and UI references to make your feature more robust:</p>
<p><pre class="brush: plain; light: true;">
Given I a have an account with email: &quot;user@test.com&quot; and password: &quot;password&quot;
When I go to the log in page
And I fill in the email field with &quot;user@test.com&quot;
And I fill in the password field with &quot;password&quot;
And I press the login button
Then I should be logged in
And I should be on the dashboard page
</pre></p>
<p>I admit that this is more work so, like most things, you need to decide what&#8217;s the most appropriate for your context. If nothing else, give some extra thought to your Then steps &#8211; are they thorough enough? are they verifying the primary business behaviour?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=261&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2011/01/26/test-business-behaviour-dont-rely-on-ui/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Faster Cucumbering With Pagination</title>
		<link>http://rubyflare.com/2010/11/25/faster-cucumbering-with-pagination/</link>
		<comments>http://rubyflare.com/2010/11/25/faster-cucumbering-with-pagination/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 06:30:50 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[pagination]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=247</guid>
		<description><![CDATA[When writing a cucumber feature that involves pagination, the easiest thing to do is to create the required number of objects to generate pagination. Given 31 tasks exist  # pagination defaults to 30 The downside of course is speed. Creating a large number of complex objects can add a lot of extra wait time to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=247&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When writing a cucumber feature that involves pagination, the easiest thing to do is to create the required number of objects to generate pagination.</p>
<blockquote>
<pre>Given 31 tasks exist  # pagination defaults to 30</pre>
</blockquote>
<p>The downside of course is speed. Creating a large number of complex objects can add a lot of extra wait time to your cucumber runs. In my case, although I only had a few scenarios that involved pagination, my per_page setting was 50 and the objects I was creating were complex. The end result was a extra couple of (unnecessary) minutes. It wasn&#8217;t too bad so I left myself a TODO to fix it one day and that day finally came.<span id="more-247"></span></p>
<p>What I wanted to do was to simply change the default per_page setting for pagination across my entire project when running my cucumber suite so that I could rewrite my steps like this:</p>
<blockquote>
<pre>Given 3 tasks exist  # pagination defaults to 2</pre>
</blockquote>
<p>This is how I set it all up:</p>
<ul>
<li>DRYed up my code by pulling out explicit settings for the per_page option and setting a project-wide per_page setting for will_paginate as a constant in my environment.rb file</li>
<li>set a different value for this constant in my test.rb file and allow it to override the default setting above</li>
<li>modify my cucumber scenarios to use the new (smaller) per_page value</li>
</ul>
<p>More specifically, I added the following to the <strong>end</strong> of config/environment.rb:</p>
<pre>unless defined? DEFAULT_PER_PAGE
  # see: http://groups.google.com/group/will_paginate/browse_thread/thread/eda47114e3127709  
  ActiveRecord::Base.instance_eval do     
    def per_page; 50; end   
  end
  DEFAULT_PER_PAGE = ActiveRecord::Base.per_page
end</pre>
<p>Then in config/environments/test.rb:</p>
<pre>ActiveRecord::Base.instance_eval do     
  def per_page; 2; end   
end
DEFAULT_PER_PAGE = ActiveRecord::Base.per_page</pre>
<p>This solution was specific to my needs. In particular, I needed a DEFAULT_PER_PAGE constant within my code. This meant I could also use it as the conditional in my environment.rb to only set the override if it hadn&#8217;t already been set. One alternative was to take this code out of environment.rb and into the specific environment files eg development.rb, production.rb. But I also have a training.rb and a staging.rb so for me I preferred to put it into the generic environment file and change the setting specifically in the test environment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/247/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=247&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2010/11/25/faster-cucumbering-with-pagination/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript Testing with Cucumber, Capybara and env.js</title>
		<link>http://rubyflare.com/2010/06/12/javascript-testing-with-cucumber-capybara-and-env-js/</link>
		<comments>http://rubyflare.com/2010/06/12/javascript-testing-with-cucumber-capybara-and-env-js/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 22:05:35 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=238</guid>
		<description><![CDATA[Tim Riley was excited when he discoved capybara and wrote an excellent blog post about Javascript Testing with Cucumber and Capybara. I was excited too but it took until I was sitting in a hallway at railsconf recharging my laptop before I found the time to clone Tim&#8217;s demo app and give capybara a try. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=238&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://openmonkey.com/">Tim Riley</a> was <a href="http://twitter.com/timriley/status/10967547994">excited</a> when he discoved c<a href="http://github.com/jnicklas/capybara">apybara</a> and wrote an excellent blog post about <a href="http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara">Javascript Testing with Cucumber and Capybara</a>. I was excited too but it took until I was sitting in a hallway at r<a href="http://en.oreilly.com/rails2010">ailsconf</a> recharging my laptop before I found the time to clone Tim&#8217;s demo app and give capybara a try. I was impressed! I ran the tests and Firefox opened up in the background, ran the test and closed almost in a blink of the eye. Wow, that was fast. So much faster than how I&#8217;ve previously tested my javascript with selenium and webrat. And no complicated setup or configuration.<span id="more-238"></span></p>
<p>Now, let me introduce you to capybara-envjs, a new gem that <a href="http://blog.josephwilk.net/">Joseph Wilk</a> described in his <a href="http://en.oreilly.com/rails2010/public/schedule/detail/14404">talk</a> at railsconf. It is a capybara driver for the envjs gem. Instead of using the selenium driver and launching a browser to perform the tests, it uses <a href="http://www.envjs.com/">envjs</a>, a simulated browser environment. That means it will be faster right? A quick experiment showed that it was. Another benefit is with running your javascript tests on a continuous integration server.</p>
<p>I&#8217;ve only just begun to play with this new setup but it looks promising. I&#8217;ve forked Tim&#8217;s original demo app and updated it to use capybara-envjs. To get it working, I added the following to cucumber&#8217;s env.rb file (in features/support):</p>
<p><pre class="brush: plain; light: true;">
Capybara.javascript_driver = :envjs
</pre></p>
<p>And then I replaced the capybara gem in the Gemfile with:</p>
<p><pre class="brush: plain; light: true;">
gem 'capybara-envjs', :require =&gt; 'capybara/envjs'
</pre></p>
<p>Easy! <a href="http://github.com/schlick/capybara-demo">Clone it and give capybara-envjs a try</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=238&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2010/06/12/javascript-testing-with-cucumber-capybara-and-env-js/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Cucumber Formatters</title>
		<link>http://rubyflare.com/2010/02/05/cucumber-formatters/</link>
		<comments>http://rubyflare.com/2010/02/05/cucumber-formatters/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 21:00:25 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[formatters]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=212</guid>
		<description><![CDATA[Cucumber allows you to format the results you get from running your features. With Cucumber 0.5, the Rails specific code was extracted out into a separate gem called cucumber-rails. With it came a smarter cucumber.yml file which now defaults to the &#8220;progress&#8221; format instead of &#8220;pretty&#8221;. This change prompted me to take a closer look [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=212&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://cukes.info/">Cucumber</a> allows you to format the results you get from running your features. With Cucumber 0.5, the Rails specific code was extracted out into a separate gem called cucumber-rails. With it came a smarter cucumber.yml file which now defaults to the &#8220;progress&#8221; format instead of &#8220;pretty&#8221;.</p>
<p><span id="more-212"></span>This change prompted me to take a closer look at the options available for formatting the output of running cucumber features. To see the full list enter in your console:</p>
<p><pre class="brush: plain; light: true;">cucumber --help</pre></p>
<p>To change the format pass either of the following:</p>
<p><pre class="brush: plain; light: true;">
cucumber --format FORMAT
cucumber -f FORMAT
</pre></p>
<p>Here&#8217;s some of the format options:</p>
<ul>
<li><strong>html</strong> &#8211; Generates an HTML version of your test results which you can save as a file and view in a browser. This is the one to use when running Cucumber inside Textmate.</li>
<li><strong>pdf</strong> &#8211; Generates a fancy formatted pdf of your test results which you can share with your clients if you wish or for archiving in your company&#8217;s records management app.</li>
<li><strong>pretty</strong> &#8211; This was originally the default format. It prints out each step of a scenario and colours it according to whether it passed, failed, was undefined or was skipped. This format provides you with the most information and is the one to use when working the red-green-refactor cycle.</li>
<li><strong>progress</strong> &#8211; This is the new default. It prints a dot for each step that passed, an F for one that failed, a U for an undefined step, and a hyphen for a skipped step.</li>
<li><strong>rerun</strong> &#8211; Prints out the failing features (with line numbers). This is now used in the default &#8220;smart&#8221; cucumber profile to setup an automatic rerun of failed scenarios. When you first use cucumber, it runs all features and scenarios. If any fail, a rerun.txt will be created that contains the output from the rerun format, a list of failed scenarios. Now when you run cucumber again, it will only run the failed scenarios instead of your entire collection of features.</li>
<li><strong>tag_cloud</strong> &#8211; Useful for showing you what tags you have used and how often.</li>
<li><strong>usage</strong> &#8211; Useful for revealing which step definitions have not been used and which are the slowest.</li>
</ul>
<p>Finally, if none of these fit your needs, you can always <a href="http://wiki.github.com/aslakhellesoy/cucumber/custom-formatters">write your own</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=212&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2010/02/05/cucumber-formatters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Pickle Tables</title>
		<link>http://rubyflare.com/2009/11/26/pickle-tables/</link>
		<comments>http://rubyflare.com/2009/11/26/pickle-tables/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 13:12:35 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[pickle]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=169</guid>
		<description><![CDATA[Following on from my original and followup articles on using Pickle with Cucumber, a brand new version of Pickle is now available. Version 0.2.0 now gives you the ability to use Pickle with Cucumber&#8217;s multiline step argument tables. This means you can now do the following with Pickle: You can quickly create multiple objects in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=169&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Following on from my <a href="http://rubyflare.com/2009/10/28/pickle-my-cucumber/">original</a> and <a href="http://rubyflare.com/2009/11/03/more-pickle-action/">followup articles</a> on using Pickle with Cucumber, a brand new version of <a href="http://github.com/ianwhite/pickle">Pickle</a> is now available. Version 0.2.0 now gives you the ability to use Pickle with Cucumber&#8217;s <a href="http://wiki.github.com/aslakhellesoy/cucumber/multiline-step-arguments">multiline step argument tables</a>. This means you can now do the following with Pickle:<br />
<pre class="brush: plain; gutter: false;">
Given a company exists
And another company: &quot;rubyflare&quot; exists
And the following people exist:
  | name  | age | employed | company              |
  | Digby | 13  | false    | the first company    |
  | Ethyl | 27  | true     | company: &quot;rubyflare&quot; |
Then the following people should exist:
  | name  | age |
  | Digby | 13  |
  | Ethyl | 27  |
And the 2nd person should be one of company: &quot;rubyflare&quot;'s employees
</pre><br />
You can quickly create multiple objects in an easy to read fashion rather than filling your scenarios with multiple lines of &#8220;an another user exists &#8230;&#8221;. As an added bonus you can also use Pickle references within these tables. In the example above, we are creating new people objects and associating them to the companies using the Pickle references for these company objects.</p>
<p>Again, I&#8217;ll just point out that the above example required no custom step definitions. I didn&#8217;t have to write any step definitions! Pickle takes care of the grunt work leaving you free to focus on your domain specific scenario steps.</p>
<p>Other recent improvements with Pickle include:</p>
<ul>
<li>an email helper for mapping names to email addresses similar to paths</li>
<li>its own separate configuration file (pickle.rb) &#8211; pickle no longer adds code to features/support/env.rb</li>
</ul>
<p>I&#8217;ve also updated my <a href="http://github.com/schlick/pickle_example">pickle_example project</a> to the latest version and have added the above example scenario. Feel free to clone it and use it to explore the benefits of using Pickle.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=169&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/11/26/pickle-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>More Pickle Action</title>
		<link>http://rubyflare.com/2009/11/03/more-pickle-action/</link>
		<comments>http://rubyflare.com/2009/11/03/more-pickle-action/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:00:11 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[pickle]]></category>

		<guid isPermaLink="false">http://rubyflare.com/?p=155</guid>
		<description><![CDATA[In a previous blogpost I championed the benefits of using Pickle with Cucumber to speed up your BDD. Recently, I was able to contribute back to Pickle in a small way with the following two changes: you can now use negative numbers in numeric field values when creating objects, and you can use some extra [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=155&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://rubyflare.com/2009/10/28/pickle-my-cucumber/">previous blogpost </a>I championed the benefits of using <a href="http://github.com/ianwhite/pickle">Pickle</a> with <a href="http://wiki.github.com/aslakhellesoy/cucumber">Cucumber</a> to speed up your BDD. Recently, I was able to contribute back to Pickle in a small way with the following two changes:</p>
<ul>
<li>you can now use <a href="http://github.com/ianwhite/pickle/commit/09521f588440efc5310ac9a208995eb51c366559">negative numbers in numeric field values</a> when creating objects, and</li>
<li>you can use some <a href="http://github.com/ianwhite/pickle/commit/3c01d71d40997fb68ce9853e2abbab5d9d45433c">extra default step definitions</a> to verify the non-existence of objects</li>
</ul>
<p>This means you can do things like this in your plain text cucumber steps:<br />
<pre class="brush: plain; light: true;">
Given a user exists with name: &quot;Digby&quot;, bank_balance: -43.25
</pre><br />
And if you need to, you can also be explicit with the positive sign:<br />
<pre class="brush: plain; light: true;">
And another user exists with name: &quot;Miranda&quot;, bank_balance: +86.50
</pre><br />
The extra step definitions allow you to do the following:<br />
<pre class="brush: plain; light: true;">
Then a user should not exist with name: &quot;Maya&quot;
And the first user should not be one of the last user's debtors
And the last user should not be the first user's creditor
</pre><br />
These are the &#8220;not&#8221; versions of some of the existing default step definitions. I found that I was needing these in my Rails projects and thought they would be good to have in the standard Pickle. Ian White, the creator of Pickle, agreed.</p>
<p>It feels good to contribute back to an open source project, even in a small way, and I encourage you all to try to do so as well.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=155&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/11/03/more-pickle-action/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Pickle my Cucumber!</title>
		<link>http://rubyflare.com/2009/10/28/pickle-my-cucumber/</link>
		<comments>http://rubyflare.com/2009/10/28/pickle-my-cucumber/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 21:00:16 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[pickle]]></category>

		<guid isPermaLink="false">http://rubyflare.wordpress.com/?p=27</guid>
		<description><![CDATA[If you are using Cucumber then I would highly recommend using Ian White&#8216;s fantastic little add-on called Pickle. Pickle makes life in the Cucumber world so much easier by providing you with convenient step definitions that take care of common object operations leaving you free to focus on the fun stuff. Combined with the pre-packaged [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=27&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://cukes.info/">Cucumber</a> then I would highly recommend using <a href="http://blog.ardes.com/ian">Ian White</a>&#8216;s fantastic little add-on called <a href="http://ianwhite.github.com/pickle">Pickle</a>.</p>
<p>Pickle makes life in the Cucumber world so much easier by providing you with convenient step definitions that take care of common object operations leaving you free to focus on the fun stuff. Combined with the pre-packaged Webrat steps you can dramatically reduce the number of step definitions you need to write.</p>
<p><span id="more-27"></span>Pickle allows you to easily create objects from your factories (<a href="http://thoughtbot.com/projects/factory_girl">Factory Girl</a>), blueprints (<a href="http://github.com/notahat/machinist/tree/master">Machinist</a>) or ActiveRecord. Here&#8217;s a simple example:<br />
<pre class="brush: plain; light: true;">
Given a person exists
</pre><br />
This simple cucumber step will use your User factory/blueprint/model to create a user object. You can also pass in specific values for your object, overriding the factory default (notice the use of the word &#8216;another&#8217;):<br />
<pre class="brush: plain; light: true;">
And another person exists with name: &quot;Digby&quot;
</pre><br />
And for multiple attributes:<br />
<pre class="brush: plain; light: true;">
And another person exists with name: &quot;Ethyl&quot;, age: 27, employed: true
</pre><br />
We can also assert the existence of an object:<br />
<pre class="brush: plain; light: true;">
Then a person should exist with name: &quot;Ethyl&quot;
</pre><br />
And you can verify the number of objects that exist:<br />
<pre class="brush: plain; light: true;">
And 3 people should exist
</pre><br />
We can now access each one of these objects and check the truth of a predicate:<br />
<pre class="brush: plain; light: true;">
And the last person should be an adult
And the 2nd person should not be employed
</pre><br />
This will assert that Ethyl is an adult eg @ethyl.adult? And finally we can label our objects for easy reference to distinguish between multiple objects of the same type:<br />
<pre class="brush: plain; light: true;">
Given a company exists
And another company: &quot;rubyflare&quot; exists
</pre><br />
Pickle can also handle associations:<br />
<pre class="brush: plain; light: true;">
And a person exists with company: company &quot;rubyflare&quot;
And another person exists with company: the first company
</pre><br />
And assertions with those associations:<br />
<pre class="brush: plain; light: true;">
Then the first person should be one of company: &quot;rubyflare&quot;'s employees
</pre><br />
Wow! That&#8217;s a lot already and all without writing a single step definition.  But wait, there&#8217;s more. Pickle also provides step definitions for email and paths. Here&#8217;s a scenario with an email cucumber step:<br />
<pre class="brush: plain; light: true;">
Given a person exists with email: &quot;fake@address.com&quot;
When I activate that person
Then 1 email should be delivered to fake@address.com
</pre><br />
The last step is provided by Pickle&#8217;s email step definitions. Now let&#8217;s look at using Pickle for paths:<br />
<pre class="brush: plain; light: true;">
Given a company exists with name: &quot;Ruby Flare&quot;
When I go to the companies page
Then I should see &quot;Listing companies&quot;
</pre><br />
Pickle adds onto the paths setup provided by Cucumber to give more generic path matchers including named routes. In this case, we are visiting the companies_path, the index action of our companies controller. Now we are going to the show action of the controller for the specified company:<br />
<pre class="brush: plain; light: true;">
When I go to the company's page
Then I should see &quot;Ruby Flare&quot;
</pre><br />
And also to a named route:<br />
<pre class="brush: plain; light: true;">
When I go to the users page
Then I should see &quot;Listing people&quot;
</pre><br />
Pickle can also handle nested routes:<br />
<pre class="brush: plain; light: true;">
When I go to the company's employees page
Then I should see &quot;Listing employees&quot;
</pre><br />
Finally, you can create custom step definitions that use Pickle methods. Earlier I had the following step:<br />
<pre class="brush: plain; light: true;">
When I activate that person
</pre><br />
This was actually a step that I had to write a step definition for:<br />
<pre class="brush: ruby; light: true;">
When /^I activate #{capture_model}$/ do |name|
  model(name).activate
end
</pre><br />
The model method is from Pickle and lets me access the object that is captured via Pickle&#8217;s #{capture_model} regexp. My step will let me match any of the following examples:<br />
<pre class="brush: plain; light: true;">
When I activate the person
When I activate the 2nd person
When I activate the person: &quot;maya&quot;
</pre><br />
There is a whole range of other Pickle regexps and additional methods like models, create_model and find_model. These allow you to create your own special step definitions leveraging off the fantastic convenience provided to you by Pickle.</p>
<p>So that&#8217;s a quick introduction to the joys of using Pickle with Cucumber. <a href="http://github.com/ianwhite/pickle">Download the gem</a>, check out the readme and the code, and start using it in your Rails projects. You can also clone a copy of my <a href="http://github.com/schlick/pickle_example">pickle_example project</a> and play around with it.</p>
<p>Pickle is an essential ingredient in my recipe for pure BDD joy. I hope you enjoy it too!</p>
<p><strong>Update (4/11/09):</strong> Ryan Bates has done a <a href="http://railscasts.com/episodes/186-pickle-with-cucumber">screencast about Pickle</a>! Go check it out.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=27&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/10/28/pickle-my-cucumber/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing Sphinx with Cucumber</title>
		<link>http://rubyflare.com/2009/09/02/testing-sphinx-with-cucumber/</link>
		<comments>http://rubyflare.com/2009/09/02/testing-sphinx-with-cucumber/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 22:00:23 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[database cleaner]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[thinking sphinx]]></category>

		<guid isPermaLink="false">http://rubyflare.wordpress.com/?p=29</guid>
		<description><![CDATA[For awhile, all of my Cucumber features that involved search were marked as TODO. The search worked but I had no integration tests for it because the default setup of Cucumber uses the transactional fixtures setting to run each scenario inside of a transaction to ensure that the database starts in the same known state [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=29&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For awhile, all of my Cucumber features that involved search were marked as TODO. The search worked but I had no integration tests for it because the default setup of Cucumber uses the transactional fixtures setting to run each scenario inside of a transaction to ensure that the database starts in the same known state for each scenario. Unfortunately ThinkSphinx won&#8217;t work with this setup. Thankfully, Brandon from <a href="http://opensoul.org">opensoul.org</a> wrote up a <a href="http://opensoul.org/2009/6/1/cucumber-scenarios-that-depend-on-sphinx">great post</a> on how to modify your Cucumber setup to get it working.</p>
<p>Further to Brandon&#8217;s post, here&#8217;s how I&#8217;ve incorporated running search features with Cucumber&#8230;<span id="more-29"></span></p>
<p>What I wanted was to keep using the standard transaction approach for my normal Cucumber features but to switch to using database cleaner for sphinx features. Now, I haven&#8217;t been able to figure out how to turn on/off the use of transactional fixtures in Cucumber.</p>
<p>To enable it you use:</p>
<p><pre class="brush: ruby; light: true;">
Cucumber::Rails.use_transactional_fixtures
</pre></p>
<p>But how do you turn it off?</p>
<p>My current solution is to pull this out of the main env.rb file and turn it on in a webrat.rb support file. This meant I needed to set up my Cucumber profiles to selectively load the appropriate support files (in cucumber.yml):</p>
<p><pre class="brush: ruby; light: true;">
default: -t ~@sphinx -r features/support/env.rb -r features/support/webrat.rb -r features/step_definitions features
sphinx: -t @sphinx -r features/support/env.rb -r features/support/sphinx.rb -r features/step_definitions features
</pre></p>
<p>I then mark all sphinx features/scenarios with the cucumber tag @sphinx. Now I can run my sphinx features using:</p>
<p><pre class="brush: plain; light: true;">
cucumber -p sphinx
</pre></p>
<p>Finally, switching back and forth between development and testing was causing me grief in starting and stopping the search daemon. The simplest solution was to assign a different port for testing (in sphinx.yml):</p>
<p><pre class="brush: ruby; light: true;">
development:
  port: 3312
test:
  port: 3313
</pre></p>
<p><strong>Update (30/9/2009):</strong></p>
<p>When I upgraded to the newest version of Cucumber (0.3.104) and ran script/generate cucumber I discovered this change in the env.rb:</p>
<p><pre class="brush: ruby; light: true;">
# Whether or not to run each scenario within a database transaction.
#
# If you leave this to true, you can turn off traqnsactions on a
# per-scenario basis, simply tagging it with @no-txn
Cucumber::Rails::World.use_transactional_fixtures = true
</pre></p>
<p>This would eliminate the need to extract the use_transactional_fixtures setting from the env.rb. Definitely worth revisiting my strategy above now.</p>
<p><strong>Update (15/10/2009)</strong>:</p>
<p>By upgrading to the latest version of Cucumber (0.4.0) I have been able to undo most of the workaround mentioned in this post. I re-generated the env.rb file using <code>ruby script/generate cucumber</code> and I removed my cucumber profiles. If I want to run only sphinx scenarios I simply use <code>cucumber -t @sphinx</code> or to run non-sphinx scenarios I use <code>cucumber -t ~@sphinx</code>. I created a <a href="http://wiki.github.com/aslakhellesoy/cucumber/browsers-and-transactions">db_cleaner.rb file</a> and I modified my sphinx.rb file removing all the database cleaner references. Finally, I add the @no-txn tag to all my scenarios which are already tagged with @sphinx. Separation of the database cleaner behaviour from the @sphinx tag means that the @no-txn stuff can be applied elsewhere as required eg selenium features.</p>
<p><strong>Update (19/12/2009)</strong>:</p>
<p>Be aware that the behaviour of tags changed with cucumber 0.4.3 to allow logical ORing and ANDing of tags. If you use tags in your profile definitions you might find you get different behaviour when you pass the @sphinx tag. My default profile is configured to exclude all scenarios and features marked with the @selenium tag. So when I run <code>cucumber -t @sphinx</code> cucumber will run all scenarios and features marked without @selenium OR with @sphinx. This results in all of my non-selenium scenarios running, not just the sphinx related ones. I still haven&#8217;t figured out a suitable fix for this however I just wanted to point this out.</p>
<p>If you don&#8217;t use profiles or don&#8217;t have tags specified in your profile then the above technique will continue to work as described above.</p>
<p><strong>Update (02/06/2010):</strong></p>
<p>As for version 1.3.2, Thinking Sphinx now provides a <a href="http://freelancing-god.github.com/ts/en/testing.html">test helper</a> for use with Cucumber. I simply add the following lines inside my features/support/sphinx.rb file:</p>
<p><pre class="brush: ruby; light: true;">
require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new
ThinkingSphinx::Test.start_with_autostop
</pre></p>
<p>Now I can remove all the startup/setup code I had previously (as show in Brandon&#8217;s original post). I also no longer need an at_exit block since that is handled by the ThinkingSphinx::Test.start_with_autostop. Now my indexing step is simply:</p>
<p><pre class="brush: ruby; light: true;">
ThinkingSphinx::Test.index
</pre></p>
<p>I have also found it necessary to add a sleep(0.25) after my indexing step to ensure that Sphinx has enough time to perform the reindex before Cucumber moves onto the next step.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=29&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/09/02/testing-sphinx-with-cucumber/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>Less Brittle View Specs</title>
		<link>http://rubyflare.com/2009/08/26/less-brittle-view-specs/</link>
		<comments>http://rubyflare.com/2009/08/26/less-brittle-view-specs/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 22:00:21 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[rails 2.3.2]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[view specs]]></category>

		<guid isPermaLink="false">http://rubyflare.wordpress.com/?p=76</guid>
		<description><![CDATA[View specs are often misunderstood and ignored (poor little things) however I believe they can be useful. A big criticism of view specs is that they are brittle &#8211; when your html changes, they break. Another is that Cucumber makes them redundant. A lot depends on how you write them. View specs aren&#8217;t about verifying that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=76&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>View specs are often misunderstood and ignored (poor little things) however I believe they can be useful. A big criticism of view specs is that they are brittle &#8211; when your html changes, they break. Another is that Cucumber makes them redundant. A lot depends on how you write them.<span id="more-76"></span></p>
<p>View specs aren&#8217;t about verifying that your html is correct or that you have applied the correct css to the appropriate dom element. Like other specs, it&#8217;s about business requirements. View specs are only brittle when you tie them closely with the presentation of your data.</p>
<p>Meanwhile, I prefer to keep my Cucumber features and step definitions free of implementation details. I just want to verify that the behaviour works, that when I do a particular task I get the outcome I expect. How it happens or how it is presented isn&#8217;t really what I care about with Cucumber &#8211; it&#8217;s an integration test after all.</p>
<p>So, I use my view specs to verify low-level business requirements like &#8220;should have a search box&#8221;. I&#8217;d use Cucumber to verify that the search box works and I&#8217;d use view specs to ensure that the search element has a title, an input field and a submit button. The view spec verifies the nitty gritty detail. For example, as a designer I could label the search any way I wish. It&#8217;s just text after all. But the business may need to use specific terminology/wording for the title and for the form element labels.</p>
<p>This is where view specs can easily become brittle. If you write them such that they depend on html elements then you are tying them to the implement of the html. If you were ever to change your html, your specs would break even though the actual business requirements would still be met. My advice is to try and eliminate all reliance on the html implementation. Focus on the business requirements.</p>
<p>Here&#8217;s a simple example&#8230;</p>
<p>The business wants a title of &#8220;Candidate Search&#8221; for their search element. It would be easy to write:<br />
<pre class="brush: ruby; light: true;">
response.should have_tag('h2', 'Candidate Search')
</pre><br />
But that has now tied the text to how the text is presented, in this case using an h2 element. What if we decide to use h3 instead? Spec fail. Try this instead:<br />
<pre class="brush: ruby; light: true;">
response.should include_text('Candidate Search')
</pre><br />
You don&#8217;t particularly care what element is used, just as long as the text appears on the page. If you need to target then do so. I like to focus on the div or id element as these (should) change less frequently. And what if the designer decides to use the button element instead of the input submit button? Fine, use an attribute selector for type=submit.</p>
<p>The thing to always keep in mind, is not to go overboard. Keep focused on the business requirements and ask whether the tests are adding any business value. I don&#8217;t test all aspects of what my views present. Remember, you should try to keep logic out of your views. I test the bits that are important to the business. Yes, there will be crossover with Cucumber features so this is where your judgement comes in.</p>
<p>Here&#8217;s my final view spec (using webrat 0.5.1 matchers):<br />
<pre class="brush: ruby; gutter: false;">
response.should have_selector('#candidate_search') do |search|
  search.should contain('Candidate Search')
  search.should have_selector('form', :action =&gt; candidates_path) do |form|
    form.should have_selector('[type=submit]')
  end
end
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=76&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/08/26/less-brittle-view-specs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
		<item>
		<title>$600 Mistake</title>
		<link>http://rubyflare.com/2009/08/12/600-mistake/</link>
		<comments>http://rubyflare.com/2009/08/12/600-mistake/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 22:00:42 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[tatft]]></category>
		<category><![CDATA[test first]]></category>

		<guid isPermaLink="false">http://rubyflare.wordpress.com/?p=72</guid>
		<description><![CDATA[Do you test? Do you test all the time (TATFT)? Can you afford to lose $600? I believe software testing is essential. Behaviour Driven Development (BDD) is something that I&#8217;m learning and incorporating into my development lifecycle. I use Cucumber and RSpec with my Rails projects to implement new features and to verify their behaviour. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=72&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Do you test? Do you test all the time (<a href="http://rubyhoedown2008.confreaks.com/05-bryan-liles-lightning-talk-tatft-test-all-the-f-in-time.html">TATFT</a>)? Can you afford to lose $600?<span id="more-72"></span></p>
<p>I believe software testing is essential. <a href="http://dannorth.net/introducing-bdd">Behaviour Driven Development</a> (BDD) is something that I&#8217;m learning and incorporating into my development lifecycle. I use <a href="http://cukes.info/">Cucumber</a> and <a href="http://rspec.info/">RSpec</a> with my Rails projects to implement new features and to verify their behaviour.</p>
<p>Aside from driving your design, validating your code, and giving you and your stakeholders confidence in your app, testing saves you money. That&#8217;s the bottom line. You might not think so. You might be able to get away with zero testing if you are extremely lucky or if you are a super coder who writes perfect software. Ultimately, the time you invest in writing tests for your code will save you time and money.</p>
<p>I recently made a small change to my <a href="http://www.scinews.com.au">SciNews</a> web application without writing a test. Why? Because it was just a small change and I was in a rush. I had opened the app in my browser and tried it out and everything was fine and dandy &#8211; deploy!</p>
<p>A month went by without any problems. Admin users of the system weren&#8217;t experiencing any issues but when a client user tried to use the service &#8211; WHAM! BAM! ERROR!! So there I was, just before midnight, on the receiving end of a support call from the client trying to figure out what just went wrong.</p>
<p>I tried to fix it on the spot but I didn&#8217;t understand the cause. The only change I made was a minor one about a month ago and admins had been using the system fine during that time. But this was the first client access since then. Aha! But unfortunately, after 15 minutes on the phone with the client, I was unable to solve the problem. As I later discovered, the bug affected client roles, not admins. When I tested it in the browser, I had done so using my admin account. I never tried it as a client.</p>
<p>In the end I had to manually perform the service for the client on their behalf. But the system had failed them and worse, it was their first use of the online service. In order to save face, compensate them for their wasted time and frustration, and to keep them as clients, the service was provided gratis. My small little insignificant change had ended up costing my business $600 and for a small, fledging business, that&#8217;s a lot of money that we can&#8217;t afford to lose. For $600, I should&#8217;ve written a test! Add in time spent on the phone with the client, the embarrassment, and the potential damage to the service&#8217;s reputation, I should&#8217;ve definitely written a test.</p>
<p>Will this client come back and try our service again? I hope so, otherwise my little error may well end up costing heaps more in lost revenue. This client may have become a repeat customer, so we&#8217;re talking a loss of $600/mth. And what about word of mouth? They might have referred two new clients. Now we&#8217;re talking some serious lost revenue here all because of one small minor change. Hopefully I&#8217;ve done enough with that client for them to give the service a second chance. Whether they do or not, I&#8217;ve learnt my lesson &#8211; TATFT!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rubyflare.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rubyflare.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rubyflare.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rubyflare.com&amp;blog=8540151&amp;post=72&amp;subd=rubyflare&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rubyflare.com/2009/08/12/600-mistake/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ccf4fe97f61701a3f2fe96a29223fa35?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">schlick</media:title>
		</media:content>
	</item>
	</channel>
</rss>
