<?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>Blog &#187; cucumber</title>
	<atom:link href="http://monket.net/blog/tag/cucumber/feed/" rel="self" type="application/rss+xml" />
	<link>http://monket.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 12 Apr 2010 13:11:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Screenshots of Failing Cucumber Scenarios</title>
		<link>http://monket.net/blog/2009/09/screenshots-of-failing-cucumber-scenarios/</link>
		<comments>http://monket.net/blog/2009/09/screenshots-of-failing-cucumber-scenarios/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 12:20:30 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snapit]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=244</guid>
		<description><![CDATA[At 7digital we use Cucumber and Watir for running acceptance tests on some of our websites. These tests can help greatly in spotting problems with configuration, databases, load balancing, etc that unit testing misses. But because the tests exercise the whole system, from the browser all the way through the the database, they can tend [...]]]></description>
			<content:encoded><![CDATA[<p>At 7digital we use <a href="http://cukes.info/">Cucumber</a> and <a href="http://wtr.rubyforge.org/">Watir</a> for running acceptance tests on some of our websites.</p>

<p>These tests can help greatly in spotting problems with configuration, databases, load balancing, etc that unit testing misses.</p>

<p>But because the tests exercise the whole system, from the browser all the way through the the database, they can tend be flakier than unit tests. Then can fail one minute and work the next, which can make debugging them a nightmare.</p>

<p>So, to make the task of spotting the cause of failing acceptance tests easier, how about we set up Cucumber to take a screenshot of the desktop (and therefore browser) any time a scenario fails.</p>

<h2>Install Screenshot Software</h2>

<p>The first thing we need to do is install something that can take screenshots. The simplest solution I found is a tiny little windows app called <a href="http://90kts.com/blog/2008/capturing-screenshots-in-watir/">SnapIt</a>. It takes a single screenshot of the primary screen and saves it to a location of your choice. No more, no less.</p>

<ul>
<li><a href="http://90kts.com/blog/wp-content/uploads/2008/06/snapit.exe">Download SnapIt</a> and save it a known location (e.g. <code>C:\Tools\SnapIt.exe</code>)</li>
</ul>

<h2>Tell Cucumber to Take a Screenshot When a Scenario Fails</h2>

<p>Now we need to tell Cucumber to take a screenshot. To do so we&#8217;ll add a function to the Cucumber <code>World</code> that will take a screenshot if needed, and run this in the <code>After</code> scenario hook. To do this modify your <code>features/support/env.rb</code> file.</p>

<h4>env.rb</h4>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> DefaultWorld
&nbsp;
  <span style="color:#008000; font-style:italic;"># Screenshot directory, relative to this env.rb file</span>
  DEFAULT_SCREENSHOT_PATH = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../../../output/cucumber/screenshots/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Absolute location of SnapIt</span>
  SNAPIT_PATH = <span style="color:#996600;">'C:<span style="color:#000099;">\\</span>Tools<span style="color:#000099;">\\</span>SnapIt.exe'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> take_screenshot_if_failed<span style="color:#006600; font-weight:bold;">&#40;</span>scenario<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>scenario.<span style="color:#9900CC;">status</span> != <span style="color:#ff3333; font-weight:bold;">:passed</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      scenario_name = scenario.<span style="color:#9900CC;">to_sexp</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span> <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\w\<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">' '</span>
      time = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;%Y-%m-%d %H%M&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      screenshot_path = <span style="color:#6666ff; font-weight:bold;">DefaultWorld::DEFAULT_SCREENSHOT_PATH</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/'</span> <span style="color:#006600; font-weight:bold;">+</span>  time <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">' - '</span> <span style="color:#006600; font-weight:bold;">+</span> scenario_name <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'.png'</span>
      cmd = <span style="color:#6666ff; font-weight:bold;">DefaultWorld::SNAPIT_PATH</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">' &quot;'</span> <span style="color:#006600; font-weight:bold;">+</span> screenshot_path <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'&quot;'</span>
      <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#008000; font-style:italic;">#{cmd}}</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>    
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># [...] Other DefaultWorld code here if needed</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
World <span style="color:#9966CC; font-weight:bold;">do</span>
  DefaultWorld.<span style="color:#9900CC;">new</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
After <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scenario<span style="color:#006600; font-weight:bold;">|</span>
  take_screenshot_if_failed<span style="color:#006600; font-weight:bold;">&#40;</span>scenario<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># [...] Other After hook code here if needed  </span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<p>Just modify the constants in the above code to point to the locations of SnapIt and a directory to save the screenshots too.</p>

<h2>What the Code Does</h2>

<p>The code will only take a screenshot if the scenario fails to pass.</p>

<p>It then extracts the name of the scenario, and converts it to a filename friendly string (e.g. <code>Monkey's should eat "things"</code> => <code>Monkey s should eat things</code>). It then prepends the current date and time, and uses this string as the filename for the screenshot.</p>

<p>This allows you to easily find screenshots for a specific scenario or time.</p>

<h2>Run a Failing Test and Check Out the Screenshot</h2>

<p>Now you can run Cucumber as normal, watch a test fail, and you should see a screenshot appear in the directory you specified. And hopefully it will help you work out what went wrong, enjoy!</p>

<p>If the screenshot fails to appear, it could be because of an error in the ruby code. But Cucumber seems to hide any execptions within the After hook, so you may need to add <code>puts</code> statements to work out what is going wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/09/screenshots-of-failing-cucumber-scenarios/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cucumber Tests as First Class Citizens in TeamCity</title>
		<link>http://monket.net/blog/2009/09/cucumber-tests-as-first-class-citizens-in-teamcity/</link>
		<comments>http://monket.net/blog/2009/09/cucumber-tests-as-first-class-citizens-in-teamcity/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 11:42:47 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[teamcity]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=226</guid>
		<description><![CDATA[TeamCity is a great continuous integration server, and has brilliant built in support for running NUnit tests. The web interface updates automatically as each test is run, and gives immediate feedback on which tests have failed without waiting for the entire suite to finish. It also keeps track of tests over multiple builds, showing you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jetbrains.com/teamcity/">TeamCity</a> is a great continuous integration server, and has brilliant built in support for running <a href="http://www.nunit.org/">NUnit</a> tests. The web interface updates automatically as each test is run, and gives immediate feedback on which tests have failed without waiting for the entire suite to finish. It also keeps track of tests over multiple builds, showing you exactly when each test first failed, how often they fail etc.</p>

<p>If like me you are using <a href="http://cukes.info/">Cucumber</a> to run your acceptance tests, wouldn&#8217;t it be great to get the same level of TeamCity integration for every Cucumber test. Well now you can, using the <code>TeamCity::Cucumber::Formatter</code> from the TeamCity 5.0 EAP release.</p>

<p>JetBrains, the makers of TeamCity, released a <a href="http://blogs.jetbrains.com/ruby/2009/08/testing-rubymine-with-cucumber/">blog post demostrating the Cucumber test integration</a>, but without any details in how to set it up yourself. So I&#8217;ll take you through it here.</p>

<h2>Getting a Copy of the TeamCity Cucumber Formatter</h2>

<p>The <a href="http://www.jetbrains.net/confluence/display/TW/TeamCity+EAP">latest TeamCity EAP</a> contains the new Cucumber Formatter hidden deep in it&#8217;s bowels. Rather than make you wade through it all, I&#8217;ve extracted the relevant files and they are available to download here:</p>

<h4><a href="http://monket.net/blog/wp-content/uploads/2009/09/TeamCityCucumberFormatter.zip">Download the TeamCity Cucumber Formatter</a></h4>

<p>The archive contains the formatter and the TeamCity library files it requires to run. Extract the archive in your project root and it will add the following files:</p>


<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">features/
    support/
        jetbrains-teamcity-formatter.rb
lib/
    teamcity/
        [some support and utility files]</pre></div></div>


<p>If you want to locate these files within the TeamCity EAP yourself, <a href="http://download.jetbrains.com/teamcity/TeamCity-10307.war">download the TeamCity 5.0 EAP War</a> file and extract it. Then from within the war unzip <code>WEB-INF/plugins/rake-runner-plugin.zip</code>. And from within the rake-runner-plugin look at <code>rake-runner/lib/rb/patch/bdd/teamcity/cucumber/formatter.rb</code> and all the files in <code>rake-runner/lib/rb/patch/common/teamcity/</code>.</p>

<p>The formatter in my download has been tweaked to look in a new location for the teamcity support files, and has been changed to be a single class in a module named <code>JBTeamCityFormatter</code> (to ease calling it from the command line).</p>

<p>The relevant changes in the file are:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
$: <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../../lib/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'teamcity/runner_common'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'teamcity/utils/service_message_factory'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'teamcity/utils/runner_utils'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'teamcity/utils/url_formatter'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> JBTeamCityFormatter <span style="color:#006600; font-weight:bold;">&lt;</span> ::<span style="color:#6666ff; font-weight:bold;">Cucumber::Ast::Visitor</span></pre></td></tr></table></div>


<h2>Setting up Cucumber to use the TeamCity Formatter</h2>

<p>Once you have the formatter installed you can use it as with any Cucumber formatter by adding it as a command line parameter:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cucumber features <span style="color: #660033;">-f</span> JBTeamCityFormatter</pre></div></div>


<p>To use it with TeamCity, add a profile your <code>cucumber.yml</code> file that runs all your features using the new formatter:</p>

<h4>cucumber.yml</h4>


<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">default: features -q 
teamcity: features -q --no-c  -f JBTeamCityFormatter</pre></div></div>


<h2>Running Cucumber with TeamCity</h2>

<p>Now when you run Cucumber within TeamCity (using the <code>teamcity</code> profile) it will report tests in real time, with all the feedback you are used to. Just add a call to the Cucumber executable to your build script (NAnt, MSBuild, Ant, Rake, etc).</p>

<p><img src="http://monket.net/blog/wp-content/uploads/2009/09/cucumber-tests-in-teamcity-cropped.png" alt="Cucumber tests in TeamCity" /></p>

<p>Enjoy the new found treatment of Cucumber tests as first class citizens in TeamCity!</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/09/cucumber-tests-as-first-class-citizens-in-teamcity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple example of Autotest, Cucumber, and Growl</title>
		<link>http://monket.net/blog/2009/06/simple-example-of-autotest-cucumber-and-growl/</link>
		<comments>http://monket.net/blog/2009/06/simple-example-of-autotest-cucumber-and-growl/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 15:47:09 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=40</guid>
		<description><![CDATA[As an example of getting Autotest, Cucumber, and Growl up and running I&#8217;ve created a super simple test project. You can download the example project, or just create it from the code on this post. Install Ruby, Growl, and Gems First up we need to ensure that we have all our dependancies installed. If you [...]]]></description>
			<content:encoded><![CDATA[<p>As an example of getting Autotest, Cucumber, and Growl up and running I&#8217;ve created a super simple test project. You can <a href="http://monket.net/blog/wp-content/uploads/2009/06/Autotest-Cucumber1.zip">download the example project</a>, or just create it from the code on this post.</p>

<h2>Install Ruby, Growl, and Gems</h2>

<p>First up we need to ensure that we have all our dependancies installed.</p>

<p>If you haven&#8217;t already, <a href="http://www.ruby-lang.org/en/downloads/">download and install Ruby</a>.</p>

<p>Then we need to install the Autotest, Cucumber, and Growl Ruby gems. We can do this using the <code>gem</code> command that comes packaged with Ruby.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Autotest test is part of the ZenTest gem</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> ZenTest
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> cucumber
<span style="color: #666666; font-style: italic;"># Use my modified autotest-growl gem (until the changes are merged into the official gem)</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> karl-autotest-growl <span style="color: #660033;">--source</span> http:<span style="color: #000000; font-weight: bold;">//</span>gems.github.com</pre></div></div>


<p>Next we need to ensure that the Growl application itself is installed. If not <a href="http://growl.info/">download and install Growl</a>.</p>

<h2>Create Project</h2>

<p>Now we are ready to create our project. The either <a href="http://monket.net/blog/wp-content/uploads/2009/06/Autotest-Cucumber1.zip">download the example project</a> or create the file heirarchy below:</p>

<ul>
<li>
[dir] Autotest-Cucumber
<ul>
<li>[file] .autotest</li>
<li>[dir] features
<ul>
<li>[file] test.feature</li>
</ul>
</li>
</ul>
</li>

</ul>

<p>Copy the code below into the <code>.autotest</code> file:</p>

<h4>.autotest</h4>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'autotest/growl'</span></pre></div></div>


<p>And the copy the following into the <code>test.feature</code> file:</p>

<h4>test.feature</h4>


<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;">Feature:
&nbsp;
    Scenario:
        Given I save 1
        Then I have 1</pre></div></div>


<h2>Set Environment</h2>

<p>Lastly we need to set the AUTOFEATURE environment variable to true, so that <a href="http://wiki.github.com/aslakhellesoy/cucumber/autotest-integration">autotest will run the Cucumber tests automatically</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">AUTOFEATURE</span>=<span style="color: #c20cb9; font-weight: bold;">true</span></pre></div></div>


<h2>Run Autotest!</h2>

<p>Finally we can run autotest, and watch as it picks up the Cucumber tests, runs them, and notifies us via Growl. Open terminal and navigate to the project directory. Then run autotest:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">autotest</pre></div></div>


<p>Autotest will initiate a Cucumber run. Cucumber will pick up the <code>test.feature</code> file (because it looks for a <code>features</code> folder by default). The Cucumber run will show that you have 1 undefined scenario (and be kind enough to give you the code for your undefined steps). And finally Growl will display a notification that you have 1 undefined scenario, yay!</p>


<div class="wp_syntax"><div class="code"><pre class="cucumber-output" style="font-family:monospace;">c:/ruby/bin/ruby c:/ruby/lib/ruby/gems/1.8/gems/aslakhellesoy-cucumber-0.3.11.3/bin/cucumber --format progress --format rerun --out C:/Temp/autotest-cucumber.17824.1 features
UU
&nbsp;
1 scenario (1 undefined)
2 steps (2 undefined)
0m0.000s
&nbsp;
You can implement step definitions for undefined steps with these snippets:
&nbsp;
Given /^I save 1$/ do
  pending
end
&nbsp;
Then /^I have 1$/ do
  pending
end</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/06/simple-example-of-autotest-cucumber-and-growl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Patched Cucumber notifications in autotest-growl gem</title>
		<link>http://monket.net/blog/2009/06/patched-cucumber-notifications-in-autotest-growl-gem/</link>
		<comments>http://monket.net/blog/2009/06/patched-cucumber-notifications-in-autotest-growl-gem/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 20:17:30 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=30</guid>
		<description><![CDATA[Following on to my previous post on Autotest, Cucumber, and Growl, I have forked the autotest-growl repository, and applied my fix for Cucumber notifications. You find my patched version of autotest-growl on GitHub. You can switch to this version of autotest-growl by uninstalling any existing version, and then installing from my fork on GitHub: sudo [...]]]></description>
			<content:encoded><![CDATA[<p>Following on to my <a href="http://monket.net/blog/2009/06/autotest-cucumber-and-growl/">previous post on Autotest, Cucumber, and Growl</a>, I have forked the autotest-growl repository, and applied my fix for Cucumber notifications.</p>

<p>You find my <a href="http://github.com/karl/autotest-growl/tree/master">patched version of autotest-growl on GitHub</a>.</p>

<p>You can switch to this version of autotest-growl by uninstalling any existing version, and then installing from my fork on GitHub:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem uninstall autotest-growl
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> karl-autotest-growl <span style="color: #660033;">--source</span> http:<span style="color: #000000; font-weight: bold;">//</span>gems.github.com</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/06/patched-cucumber-notifications-in-autotest-growl-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autotest, Cucumber, and Growl</title>
		<link>http://monket.net/blog/2009/06/autotest-cucumber-and-growl/</link>
		<comments>http://monket.net/blog/2009/06/autotest-cucumber-and-growl/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 06:19:17 +0000</pubDate>
		<dc:creator>Karl O&#39;Keeffe</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[autotest]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://monket.net/blog/?p=3</guid>
		<description><![CDATA[Autotest is a great Ruby tool to speed up test driven development by automatically running your tests every time a file is saved. Cucumber is an awesome tool for doing behavioural driven development. It allows you to write plain text automated acceptance tests. Autotest and Cucumber work together seamlessly, you just need to set the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ph7spot.com/articles/getting_started_with_autotest">Autotest</a> is a great Ruby tool to speed up test driven development by automatically running your tests every time a file is saved.</p>

<p><a href="http://cukes.info/">Cucumber</a> is an awesome tool for doing behavioural driven development. It allows you to write plain text automated acceptance tests.</p>

<p><a href="http://wiki.github.com/aslakhellesoy/cucumber/autotest-integration">Autotest and Cucumber work together seamlessly</a>, you just need to set the <code>AUTOFEATURE</code> environment variable to true:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">AUTOFEATURE</span>=<span style="color: #c20cb9; font-weight: bold;">true</span></pre></div></div>


<p><a href="http://growl.info/">Growl</a> is an excellent notification system for OSX that allows applications to popup unobtrusive messages on the users desktop. (<a href="http://www.fullphat.net/index.php">Snarl</a> is the equivalent for windows)</p>

<p>You can <a href="http://github.com/svoop/autotest-growl/tree/master">add Growl support to Autotest (using the autotest-growl gem)</a> so that you get popup notifications of test results.</p>

<p><b>But the current version of autotest-growl doesn&#8217;t provide notifications for the result of Autotest Cucumber runs.</b></p>

<h2>Cucumber Growl support in Autotest</h2>

<p>So I&#8217;ve added support for notification of Autotest Cucumber results using growl. It&#8217;s super simple at the moment as I&#8217;m still pretty new at Ruby.</p>

<p>You need to have Autotest (part of the ZenTest gem), Autotest-Growl, and Growl already installed.</p>

<p>Save the code below to the file <code>growl-cucumber.rb</code>.</p>

<h4>growl-cucumber.rb</h4>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'autotest'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">Autotest::Growl</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Growl results of Cucumber</span>
  Autotest.<span style="color:#9900CC;">add_hook</span> <span style="color:#ff3333; font-weight:bold;">:ran_features</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>autotest<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
	gist = autotest.<span style="color:#9900CC;">results</span>.<span style="color:#9900CC;">grep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>\s<span style="color:#006600; font-weight:bold;">+</span>scenario.<span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; / &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">if</span> gist == <span style="color:#996600;">''</span>
	  growl <span style="color:#0066ff; font-weight:bold;">@label</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'Cannot run features.'</span>, <span style="color:#996600;">''</span>, <span style="color:#996600;">'error'</span>
	<span style="color:#9966CC; font-weight:bold;">else</span>
	  <span style="color:#9966CC; font-weight:bold;">if</span> gist =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>\d<span style="color:#006600; font-weight:bold;">*</span>\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>failed<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
	    growl <span style="color:#0066ff; font-weight:bold;">@label</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'Some features have failed.'</span>, gist, <span style="color:#996600;">'failed'</span>
	  <span style="color:#9966CC; font-weight:bold;">elsif</span> gist =~ <span style="color:#006600; font-weight:bold;">/</span>pending<span style="color:#006600; font-weight:bold;">/</span>
	    growl <span style="color:#0066ff; font-weight:bold;">@label</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'Some features are skipped.'</span>, gist, <span style="color:#996600;">'skipped'</span>
	  <span style="color:#9966CC; font-weight:bold;">else</span>
	    growl <span style="color:#0066ff; font-weight:bold;">@label</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'All features have passed.'</span>, gist, <span style="color:#996600;">'passed'</span>
	  <span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<p>Then update your .autotest configuration file to include the new growl-cucumber file:</p>

<h4>.autotest</h4>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Add the growl and growl-cucumber requires to your .autotest config file </span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'autotest/growl'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'autotest/growl-cucumber'</span></pre></div></div>


<hr />

<h2>To Do</h2>

<p>I need to see if this can be integrated with the existing autotest-growl gem.</p>
]]></content:encoded>
			<wfw:commentRss>http://monket.net/blog/2009/06/autotest-cucumber-and-growl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

