<?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>Giordano Scalzo&#039;s Personal Blog &#187; bdd</title>
	<atom:link href="http://giordano.scalzo.biz/category/bdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://giordano.scalzo.biz</link>
	<description>Just another useless weblog</description>
	<lastBuildDate>Fri, 09 Jul 2010 09:41:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AgileCamp 2010: richness of difference</title>
		<link>http://giordano.scalzo.biz/2010/03/17/agilecamp-2010-richness-of-differerence/</link>
		<comments>http://giordano.scalzo.biz/2010/03/17/agilecamp-2010-richness-of-differerence/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:59:01 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[me]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[barcamp]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=288</guid>
		<description><![CDATA[Some weeks ago, I has been lucky enough to attend to AgileCamp 2010, an awesome Barcamp organized by Sketchin, a Swiss UX and Web agency.
With my good fellows XpUg-gers Gabriele, Andrea and Indrit, we reached a lot of old and new friends, all of them caring about quality and &#8220;Things Got Right&#8221;.
I came back really [...]]]></description>
			<content:encoded><![CDATA[<p>Some weeks ago, I has been lucky enough to attend to <a href="http://barcamp.org/AgileCamp">AgileCamp 2010</a>, an awesome <a href="http://barcamp.org/">Barcamp </a>organized by <a href="http://www.sketchin.ch/it/blog/sketchin/vorremo-parlarvi-dellagilecamp2010.html">Sketchin</a>, a Swiss UX and Web agency.<br />
With my good fellows <a href="http://milano-xpug.pbworks.com/">XpUg-gers</a> <a href="http://www.gabrielelana.it/">Gabriele</a>, <a href="http://blog.andreafrancia.it/">Andrea</a> and <a href="http://it.linkedin.com/in/indritselimi">Indrit</a>, we reached a lot of old and new friends, all of them caring about quality and &#8220;<em>Things Got Righ</em>t&#8221;.<br />
I came back really enriched, mainly because I met people with experiences and point of view different than mine.</p>
<p>It has been my first <a href="http://barcamp.org/">Barcamp</a>, so I though it was necessary to present something, and I decided to assemble a little introduction to Tdd coding for Iphone.</p>
<p>Here there is the video of my presentation:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="320" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=10062595&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="320" src="http://vimeo.com/moogaloop.swf?clip_id=10062595&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://vimeo.com/10062595">AgileCamp &#8211; iPhone agile DEV (di Giordano Scalzo)</a> from <a href="http://vimeo.com/sketchin">Sketchin</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/barcamp' rel='tag' target='_self'>barcamp</a>, <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/iphone' rel='tag' target='_self'>iphone</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2010/03/17/agilecamp-2010-richness-of-differerence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StringCalculator Kata at Xpug</title>
		<link>http://giordano.scalzo.biz/2009/12/17/stringcalculator-kata-at-xpug/</link>
		<comments>http://giordano.scalzo.biz/2009/12/17/stringcalculator-kata-at-xpug/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 13:18:20 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[xpug]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=255</guid>
		<description><![CDATA[Last evening the wonderful Xpug Milano hosted a Kata Meeting: three people, three language, one problem, one pomodoro each!
After the launch of http://katacasts.com/, this kind of practice has begun to spread around the world.
As far as I know, that was one of the firsts meeting held in Italy and it has been exciting (and a [...]]]></description>
			<content:encoded><![CDATA[<p>Last evening the wonderful Xpug Milano hosted a Kata Meeting: three people, three language, one problem, one pomodoro each!</p>
<p>After the launch of <a href="http://katacasts.com/">http://katacasts.com/</a>, this <a href="http://rubyconf2008.confreaks.com/ruby-kata-and-sparring.html">kind of practice</a> has begun to spread around the world.</p>
<p>As far as I know, that was one of the firsts meeting held in Italy and it has been exciting (and a little scaring) to be one of the performer.</p>
<p>The simple problem to solve was the <a href="http://osherove.com/tdd-kata-1/">StringCalculator</a> kata, proposed by <a href="http://osherove.com">Roy Osherove</a> as simple exercise to repeat to assimilate Tdd.</p>
<p><a href="http://twitter.com/lucamarrocco">Luca Marrocco</a> performed the <a href="http://www.vimeo.com/8087998">kata in Ruby</a>, <a href="http://bitbucket.org/rsalmaso/">Raffaele Salmaso</a> a <a href="http://bitbucket.org/rsalmaso/">Python version</a>, <a href="http://www.gabrielelana.it/">the benevolent dictator of Xpug Milano</a> a backup <a href="http://www.vimeo.com/8206748">kata in Erlang</a>, and yours truly a Scala version.</p>
<p>Below the live recording of my session, with errors, mistakes and pauses made during the execution:</p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8235576&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8235576&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/8235576">StringCalculator in Scala Kata live at Xpug Milano</a> from <a href="http://vimeo.com/user2802092">giordano scalzo</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Any kind of suggestion about the solution, the process, the way I performed are absolutely welcome.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/scala' rel='tag' target='_self'>scala</a>, <a class='technorati-link' href='http://technorati.com/tag/xpug' rel='tag' target='_self'>xpug</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/12/17/stringcalculator-kata-at-xpug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An evening at Xpug: Bdd presentation</title>
		<link>http://giordano.scalzo.biz/2009/12/04/an-evening-at-xpug-bdd-presentation/</link>
		<comments>http://giordano.scalzo.biz/2009/12/04/an-evening-at-xpug-bdd-presentation/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 21:24:48 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[me]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[xpug]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=249</guid>
		<description><![CDATA[Last evening, I gave a speech about Bdd, at the wonderful Milan XPUg.
The meeting has been very pleasant: I believe the members are among the most brilliant mind I know.
I could admit I didn&#8217;t know very well Bdd, but following the good old advice &#8220;teach to learn&#8220;, I got a triple win:
I taught something new [...]]]></description>
			<content:encoded><![CDATA[<p>Last evening, I gave a speech about Bdd, at the wonderful <a href="http://milano-xpug.pbworks.com/">Milan XPUg</a>.<br />
The meeting has been very pleasant: I believe the members are among the most brilliant mind I know.</p>
<p>I could admit I didn&#8217;t know very well Bdd, but following the good old advice &#8220;<em>teach to learn</em>&#8220;, I got a triple win:<br />
I taught something new to Xpug guys, I learned a lot of new things and I improved my presentation skill.</p>
<p>Moreover, after a couple of hours after I put online my slides, the Slideshare team promoted my presentation in home page as features presentation: what a great result for a weekend presentation hack!</p>
<div style="width:425px;text-align:left" id="__ss_2642417"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/giordano/bdd-tdd-and-beyond-the-infinite" title="Bdd: Tdd and beyond the infinite">Bdd: Tdd and beyond the infinite</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=2642417&#038;stripped_title=bdd-tdd-and-beyond-the-infinite" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=2642417&#038;stripped_title=bdd-tdd-and-beyond-the-infinite" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/giordano">giordano scalzo</a>.</div>
</div>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/presentation' rel='tag' target='_self'>presentation</a>, <a class='technorati-link' href='http://technorati.com/tag/xpug' rel='tag' target='_self'>xpug</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/12/04/an-evening-at-xpug-bdd-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My solution to RPCFN 2</title>
		<link>http://giordano.scalzo.biz/2009/10/20/my-solution-to-rpcfn-2/</link>
		<comments>http://giordano.scalzo.biz/2009/10/20/my-solution-to-rpcfn-2/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 12:22:03 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[RPCFN]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=188</guid>
		<description><![CDATA[The solutions for RPCFN 2 are now under judgement, so it&#8217;s the time to show my effort.
The problem was easy, but a little tricky: given a list of time of day, the program should find the average time.
The tricky part was to manage &#8220;am&#8221; and &#8220;pm&#8221; times, mapping them in date format: given &#8220;11:59am&#8221; and [...]]]></description>
			<content:encoded><![CDATA[<p>The solutions for <a href="http://rubylearning.com/blog/2009/10/08/rpcfn-average-arrival-time-for-a-flight-2/">RPCFN 2</a> are now under judgement, so it&#8217;s the time to show my effort.</p>
<p>The problem was easy, but a little tricky: given a list of time of day, the program should find the average time.<br />
The tricky part was to manage &#8220;am&#8221; and &#8220;pm&#8221; times, mapping them in date format: given &#8220;11:59am&#8221; and &#8220;12:00am&#8221;, then average time should be midnight.</p>
<p>My solution is based on the principle than if the range between &#8220;am&#8221; and &#8220;pm&#8221; times is under half a day, they are in the same day, otherwise a day leap occurs; this approach worked well, althought it needed a little bit of explanation in code, as <a href="http://rubylearning.com/blog/2009/10/08/rpcfn-average-arrival-time-for-a-flight-2/comment-page-1/#comment-119656">noted by Chris himself</a> <img src='http://giordano.scalzo.biz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>These are my spec:</p>
<pre class='brush: ruby'>
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'average_time_of_day'

describe 'average_time_of_day' do
	context 'for "06:00pm" and "07:00pm"' do
		it 'should be "06:30pm"' do
			avg = average_time_of_day(["06:00pm", "07:00pm"])
			avg.should == "06:30pm"
		end
	end
	context 'for "06:00pm", "07:00pm" and "08:00pm' do
		it 'should be "07:00pm"' do
			avg = average_time_of_day(["06:00pm", "07:00pm", "08:00pm"])
			avg.should == "07:00pm"
		end
	end
	context 'for "06:41am", "06:51am" and "07:01am' do
		it 'should be "06:51am"' do
			avg = average_time_of_day(["06:41am", "06:51am", "07:01am"])
			avg.should == "06:51am"
		end
	end

	context 'for "23:59pm" and "12:01am' do
		it 'should be "12:00am"' do
			avg = average_time_of_day(["23:59pm", "00:01am"])
			avg.should == "12:00am"
		end
	end

	context 'for "11:51pm", "11:56pm", "12:01am", "12:06am" and  "12:11am"' do
		it 'should be "12:01am"' do
			avg = average_time_of_day(["11:51pm", "11:56pm", "12:01am", "12:06am", "12:11am"])
			avg.should == "12:01am"
		end
	end

	context 'for "11:15pm", "12:03am", "11:30pm", "11:23pm", "11:48pm"' do
		it 'should be "11:35pm"' do
			avg = average_time_of_day(["11:15pm", "12:03am", "11:30pm", "11:23pm", "11:48pm"])
			avg.should == "11:35pm"
		end
	end

	context 'for "05:15am", "06:03am", "05:30am", "05:23am", "05:48am"' do
		it 'should be "05:35am"' do
			avg = average_time_of_day(["05:15am", "06:03am", "05:30am", "05:23am", "05:48am"])
			avg.should == "05:35am"
		end
	end

	context 'for "11:15am", "12:03pm", "11:30am", "11:23am", "11:48am"' do
		it 'should be "11:35am"' do
			avg = average_time_of_day(["11:15am", "12:03pm", "11:30am", "11:23am", "11:48am"])
			avg.should == "11:35am"
		end
	end

	context 'for "6:00pm" and "6:00am' do
		it 'should be "12:00am"' do
			avg = average_time_of_day(["6:00pm", "6:00am"])
			avg.should == "12:00am"
		end
	end

	context 'for "12:01am", "11:51pm", "11:56pm",  "12:06am" and  "12:11am"' do
		it 'should be "12:01am"' do
			avg = average_time_of_day(["12:01am", "11:51pm", "11:56pm", "12:06am", "12:11am"])
			avg.should == "12:01am"
		end
	end

end
</pre>
<p>and this are my code:</p>
<pre class='brush: ruby'>
require 'time'

private
class Array
	def to_sec
		map {|t|t.to_f}
	end

	def avg
		(size > 0) ? to_sec.inject(0.0){|sum,el| sum + el}/size : 0

	end
end

class Time
	def am?
		hour < 12
	end

	def pm?
		not am?
	end

	def to_s
		strftime("%I:%M%p").downcase
	end

end

DAY_IN_SEC = 24*60*60

def adjust_order_for(times)
	to_adjust?(times) ? adjusted(times) : times
end

def to_adjust?(times)
	avg_am = times.select { |t| t.am? }.avg
	avg_pm = times.select { |t| t.pm? }.avg
	avg_pm - avg_am  >= DAY_IN_SEC/2
end

def adjusted(times)
	times.map { |t|(t.am? ? t+DAY_IN_SEC : t) }
end

public
def average_time_of_day(times)
	times = adjust_order_for(times.map { |t| Time.parse(t) })

	Time.at(times.avg).to_s
end
</pre>
<p>Next Quiz is scheduled for 1st Nov. 2009, and will be provided by <a href="http://gautamrege.wordpress.com/">Gautam Rege</a>.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/RPCFN' rel='tag' target='_self'>RPCFN</a>, <a class='technorati-link' href='http://technorati.com/tag/ruby' rel='tag' target='_self'>ruby</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/10/20/my-solution-to-rpcfn-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gibbon: add story to RSpec</title>
		<link>http://giordano.scalzo.biz/2009/10/15/gibbon-add-story-to-rspec/</link>
		<comments>http://giordano.scalzo.biz/2009/10/15/gibbon-add-story-to-rspec/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 08:31:33 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=184</guid>
		<description><![CDATA[I really do like Rspec and so do Cucumber, but, often, I don&#8217;t like switch between them during my develompment.
Today I stumbled upon &#8216;Gibbon&#8216; a clever hack by Stephen Caudill, of tomatoi.st fame,
that add support for GIVEN/WHEN/THEN templates.
It simple needs to add this file into your spec/support directory:

module Spec::DSL::Main
  alias :Feature :describe
  def [...]]]></description>
			<content:encoded><![CDATA[<p>I really do like Rspec and so do Cucumber, but, often, I don&#8217;t like switch between them during my develompment.<br />
Today I stumbled upon &#8216;<a href="http://gist.github.com/206969">Gibbon</a>&#8216; a clever hack by <a href="http://blog.voxdolo.me/">Stephen Caudill</a>, of <a href="http://tomatoi.st">tomatoi.st</a> fame,<br />
that add support for <code>GIVEN/WHEN/THEN</code> templates.</p>
<p>It simple needs to add this file into your spec/support directory:</p>
<pre class='brush: ruby'>
module Spec::DSL::Main
  alias :Feature :describe
  def Story(description)
    @description_args.push("\n#{description}\n")
  end
end

module Spec::Example::ExampleGroupMethods
  def executes(scope=:all, &#038;blk)
    before(scope, &#038;blk)
  end

  def Scenario(description, &#038;blk)
    describe("Scenario:  #{description}", &#038;blk)
  end

  def Background(description, &#038;blk)
    describe("Background #{description}", &#038;blk)
  end

  def Given(description, &#038;blk)
    describe("Given #{description}", &#038;blk)
  end

  def When(description, &#038;blk)
    describe("When #{description}", &#038;blk)
  end

  def Then(description, &#038;blk)
    example("Then #{description}", &#038;blk)
  end

  def And(description, &#038;blk)
    example("And #{description}", &#038;blk)
  end

  def But(description, &#038;blk)
    example("But #{description}", &#038;blk)
  end
end
</pre>
<p>and it&#8217;ll be possible write specs like that:</p>
<pre class='brush: ruby'>
  Feature "A Tomatoist does a pomodoro" do
    Story <<-eos
    In order to perform a focused unit of work
    As a Tomatoist
    I want to start a pomodoro
    eos

    Scenario "Starting a pomodoro" do
      When "I go to the home page" do
        executes { visit '/' }

        Then "I should be sent to a new session" do
          current_url.should =~ /\/\w{3,}/
        end

        And "I should see an unstarted timer" do
          response.should have_tag('#timer .countdown_row','00:00')
        end

        And "I should see a pomdoro button" do
          response.should have_tag('input[type=submit][value=?]','Pomdoro')
        end

        When "I click the pomodoro button" do
          executes do
            @session_url = current_url
            click_button 'Pomodoro'
          end

          Then "I should be on my session's page" do
            current_url.should == @session_url
          end

          And "my timers should have been initialized" do
            response.should have_tag('#timer .countdown_row','25:00')
          end

          And "my timer history should show the current pomdoro" do
            response.should have_tag('#history ul li', /Pomodoro/, 1)
          end

          And "the pomodoro button should be highlighted" do
            response.should have_tag('form.current input[type=submit][value=?]','Pomdoro')
          end
        end
      end
    end
  end
  </pre>
<p>  Neat hack, indeed!</p>
<p>  I'll try it as soon as possible.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/ruby' rel='tag' target='_self'>ruby</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/10/15/gibbon-add-story-to-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bowling Kata with Ruby and RSpec</title>
		<link>http://giordano.scalzo.biz/2009/09/22/bowling-kata-with-ruby-and-rspec/</link>
		<comments>http://giordano.scalzo.biz/2009/09/22/bowling-kata-with-ruby-and-rspec/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 18:59:34 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[bowling]]></category>
		<category><![CDATA[kata]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=117</guid>
		<description><![CDATA[Looking around in daily feeds reading, suddenly I realized I never practiced the first code kata: that Bowling Kata that started all.
I decided to implement it while exploring RSpec and configuring my Ruby environment for Windows:
I used to do my programming under  friendly Ubuntu, but  because my recent jobs duties in Delphi, mainly [...]]]></description>
			<content:encoded><![CDATA[<p>Looking around in daily feeds reading, suddenly I realized I never practiced the first code kata: that <a href="http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata">Bowling Kata</a> that started all.<br />
I decided to implement it while exploring RSpec and configuring my Ruby environment for Windows:<br />
I used to do my programming under  friendly Ubuntu, but  because my recent jobs duties in Delphi, mainly I use a Windows Xp system.</p>
<p>Installing Ruby is straightforward thanks to <a href="http://rubyinstaller.org/">RubyInstaller</a>, a wonderful project that let you configure a Ruby environment under Windows; to dive into a complete Bdd flow I configured <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">autospec</a> and <a href="http://www.growlforwindows.com/gfw/default.aspx">Growl</a> following this useful <a href="http://monket.net/blog/2009/07/autotest-growl-for-windows/">post</a>: I advice every Bdd practitioner to give <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">autospec</a> a try, it can save a lot of windows and mental switch&#8230; but it can&#8217;t be told, try it and enjoy it.</p>
<p>While I&#8217;m very happy with Eclipse during Java coding, I never found a satisfactory editor for Ruby code.<br />
So I decided to try to enter in guru world and use <a href="http://www.vim.org/">Vim</a>,  adding a bunch of useful plugin, as the wondeful <a href="http://www.vim.org/scripts/script.php?script_id=2540">snipMate</a> that import the Textmate snippets under Vim.</p>
<p>Back to kata, these are my specs:</p>
<pre class='brush: ruby'>
require File.join(File.dirname(__FILE__), "//spec_helper")

describe Bowling do

	before(:each) do
		@game = Bowling.new
	end

	def roll_many(num, pins)
		num.times do |hit|
			@game.hit(pins)
		end
	end

	it "should score 0 for gutter game" do
		roll_many(20, 0)
		@game.score.should == 0
	end

	it "should score 20 for a pin each frame" do
		roll_many(20, 1)
		@game.score.should == 20
	end

	def roll_spare()
		@game.hit(5)
		@game.hit(5)
	end

	it "should score 20 when make a spare and 3 and 4 after " do
		roll_spare
		@game.hit(3)
		@game.hit(4)
		roll_many(16, 0)
		@game.score.should == 20
	end

	def roll_strike()
		@game.hit(10)
	end

	it "should score 24 when make a strike and 3 and 4 after " do
		roll_strike
		@game.hit(3)
		@game.hit(4)
		roll_many(16, 0)
		@game.score.should == 24
	end
end
</pre>
<p>They are virtually identical to UncleBob&#8217;s ones.</p>
<p>And this is my code:</p>
<pre class='brush: ruby'>
class Bowling
	private
	class Frame
		def initialize
			@rolls = []
			@rolls[0] = @rolls[1] = 0
			@index = 0
		end

		def sum
			@rolls[0]+@rolls[1]
		end

		def strike?
			@rolls[0] == 10
		end

		def spare?
			sum == 10 &#038;&#038; !strike?
		end

		def bonus_for_strike
			sum
		end

		def bonus_for_spare
			@rolls[0]
		end

		def pins=(value)
			@rolls[@index] = value
			@index = @index + 1
		end

		def finished?
			@index > 1 || strike?
		end

	end

	def add_frame?
		@frames.empty? || @frames.last.finished?
	end

	public

	def initialize
		@frames = []
	end

	def hit(pins)
		@frames << Frame.new if add_frame?
		@frames.last.pins=pins
	end

	def score
		was_spare = false
		was_strike = false
		@frames.inject(0) do |score, current_frame|
			if(was_strike)
				score = score + current_frame.bonus_for_strike
			end
			if(was_spare)
				score = score + current_frame.bonus_for_spare
			end
			was_spare = current_frame.spare?
			was_strike = current_frame.strike?

			score + current_frame.sum

		end
	end
end
</pre>
<p>I'm quite satisfied for the result, I like the encapsulation of responsibility inside <code>Frame</code>, but I don't like at all the fact I saved a state during the score's calculation: I will focus on that in next practice.  </p>
<p>At last, the environment created has been very friendly, I didn't miss Eclipse for normal developing, maybe I miss a bit a helper for extracting method, but with snippets and the Vim shortcuts, I gained a lot of productivity.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/bowling' rel='tag' target='_self'>bowling</a>, <a class='technorati-link' href='http://technorati.com/tag/kata' rel='tag' target='_self'>kata</a>, <a class='technorati-link' href='http://technorati.com/tag/rspec' rel='tag' target='_self'>rspec</a>, <a class='technorati-link' href='http://technorati.com/tag/ruby' rel='tag' target='_self'>ruby</a>, <a class='technorati-link' href='http://technorati.com/tag/vi' rel='tag' target='_self'>vi</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/09/22/bowling-kata-with-ruby-and-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JDave: A quick introduction to specs framework</title>
		<link>http://giordano.scalzo.biz/2009/09/17/using-jdave-a-quick-introduction-to-specs-framework/</link>
		<comments>http://giordano.scalzo.biz/2009/09/17/using-jdave-a-quick-introduction-to-specs-framework/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 15:13:47 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[jdave]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=90</guid>
		<description><![CDATA[As second Bdd engine to try, I choose JDave, a specification oriented engine.
JBehave is, instead, user-stories-oriented: the difference is very subtle and I&#8217;m not sure I caught it completely  .
Anyway, JDaveis inspired by RSpec, at the moment the most used bdd engine, so I thought it deserved a try.
In order to compare JDave with [...]]]></description>
			<content:encoded><![CDATA[<p>As second Bdd engine to try, I choose <a href="http://www.jdave.org/">JDave</a>, a specification oriented engine.<br />
<a href="http://jbehave.org/">JBehave </a>is, instead, user-stories-oriented: the difference is very subtle and I&#8217;m not sure I caught it completely <img src='http://giordano.scalzo.biz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .<br />
Anyway, <a href="http://www.jdave.org/">JDave</a>is inspired by <a href="http://rspec.info/">RSpec</a>, at the moment the most used bdd engine, so I thought it deserved a try.<br />
In order to compare <a href="http://www.jdave.org/">JDave</a> with <a href="http://jbehave.org/">JBehave</a>, I implemented the StringTemplater kata, as in my <a href="http://giordano.scalzo.biz/2009/09/04/bdd-with-jbehave/">previous post</a>.</p>
<h3>Installing JDave</h3>
<p>After creating a java project, I simply downloaded the <a href="http://www.jdave.org/resources.html">last version of JDave</a> and extracted all jar in lib directory of my project:</p>
<p><img src="http://giordano.scalzo.biz/wp-content/uploads/2009/09/bdd.png" alt="JDave Jars" title="JDave Jars" width="259" height="441" class="aligncenter size-full wp-image-97" /></p>
<p>They are a lot of jars, and I&#8217;m sure I won&#8217;t use all of them, but it&#8217;s just a try so it doesn&#8217;t deserve the time to filter only the used ones.</p>
<p><a href="http://jbehave.org/">JBehave</a> is a story runner, so each scenario must be written as:</p>
<pre><strong>Given</strong> something
<strong>When </strong>something happens
<strong>Then </strong>this happens</pre>
<p>Instead, <a href="http://www.jdave.org/">JDave</a> is a specification engine and each scenario show a behavior of a class:</p>
<pre>AThingIWantToWrite
  - ShouldDoThis
  - ShouldDoThat
  - ShouldntDoThat</pre>
<p>In other words, <a href="http://jbehave.org/">JBehave</a> is similar to <a href="http://cukes.info/">Cucumber</a>, <a href="http://www.jdave.org/">JDave</a> is similar to <a href="http://rspec.info/">RSpec</a>.</p>
<p>Writing a specification is really straightforward:<br />
first of all, we create a <code>Specification </code>object, passing the object we want to write; then we create a serie of inner classes:</p>
<pre class="brush: java">@RunWith(JDaveRunner.class)
public class StringTemplaterSpec extends Specification&lt;ThingIWantToWrite&gt; {
	public class AThingIWantToWrite {
		public void ShouldDoThis() {
		}
		public void ShouldDoThat() {
		}
        }
   ...
}</pre>
<p>As <a href="http://jbehave.org/">JBehave</a>, <a href="http://www.jdave.org/">JDave</a> is a wrapper built over JUnit, so we can use our Ide integration to run the specifications.<br />
That&#8217;s it!</p>
<h3>The code</h3>
<p>As in <a href="http://giordano.scalzo.biz/2009/09/04/bdd-with-jbehave/">JBehave try</a>, I implemented the same scenarios as in Corey Haines Video:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jdave;

import org.junit.runner.RunWith;

import jdave.Specification;
import jdave.junit4.JDaveRunner;

@RunWith(JDaveRunner.class)
public class StringTemplaterSpec extends Specification&lt;StringTemplater&gt; {
	public class AStringTemplater {
		private StringTemplater stringTemplater;

		public void create() {
			stringTemplater = new StringTemplater();
		}

		public void shouldReturnEmptyWhenAnEmptyStringIsPassed() {
			specify(stringTemplater.replace(""), must.equal(""));
		}

		public void shouldReturnTheOriginalStringWhenNoMarkersArePassed() {
			specify(stringTemplater.replace("original string"), must.equal("original string"));
		}

		public void shouldReplaceAToken() {
			specify(stringTemplater.replace("Hello, $name","name: giordano"),
					must.equal("Hello, giordano"));
		}

		public void shouldReplaceTwoTokens() {
			specify(stringTemplater.replace("Hello, $name, how a $attitude day","name: giordano, attitude:  wonderful"),
					must.equal("Hello, giordano, how a wonderful day"));
		}

		public void shouldRemoveNotProvidedMarkers() {
			specify(stringTemplater.replace("Hello, $name, how a $attitude day","name: giordano"),
					must.equal("Hello, giordano, how a  day"));
		}
	}

}</pre>
<p>The Junit view of Eclipse is very explicative of the behaviors of StringTemplater:<br />
<img src="http://giordano.scalzo.biz/wp-content/uploads/2009/09/junit_view.png" alt="JUnit View" title="JUnit View" width="491" height="326" class="aligncenter size-full wp-image-98" /></p>
<p>For sake of completeness, this is the final implementation of StringTemplater:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jdave;

import java.util.Arrays;
import java.util.Iterator;

public class StringTemplater {

	public String replace(String stringToReplace) {
		return replace(stringToReplace, "");
	}

	public String replace(String stringToReplace, String markers) {
		return replace(stringToReplace, initialIterator(markers));
	}

	private String[] tupla(String pair) {
		return pair.split(":");
	}

	private Iterator&lt;String&gt; initialIterator(String markers) {
		return Arrays.asList(markers.split(",")).iterator();
	}

	private String replace(String stringToReplace, Iterator&lt;String&gt; markers) {
		if (!markers.hasNext())
			return stringToReplace;
		String[] pair = tupla(markers.next());
		String newString = stringToReplace.replace(name(pair), value(pair));
		return replaceEmptyMarkers(replace(newString, markers));
	}

	private String replaceEmptyMarkers(String replace) {
		return replace.replaceAll("\\$\\w+", "");
	}

	private String value(String[] pair) {
		return (pair.length != 2) ? "" : pair[1].trim();
	}

	private String name(String[] pair) {
		if (pair.length != 2)
			return "";
		return "$" + pair[0].trim();
	}
}</pre>
<h3>Conclusions</h3>
<p><a href="http://www.jdave.org/">JDave</a> is very easy to learn and the specifications written throught it are very complete and expressive.<br />
If I have to make a choice, I liked slightly more <a href="http://www.jdave.org/">JDave</a>, but I think are just two tools: BDD is a way to think, not a framework or an engine to use.</p>
<p>In conclusions, I believe <a href="http://jbehave.org/">JBehave </a>and <a href="http://www.jdave.org/">JDave</a> could be used together, the former to describe the user stories, at user level, the latter to describe the behaviors of the classes, at developer level.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/eclipse' rel='tag' target='_self'>eclipse</a>, <a class='technorati-link' href='http://technorati.com/tag/java' rel='tag' target='_self'>java</a>, <a class='technorati-link' href='http://technorati.com/tag/jdave' rel='tag' target='_self'>jdave</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/09/17/using-jdave-a-quick-introduction-to-specs-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Infinitest: an autotest for Eclipse</title>
		<link>http://giordano.scalzo.biz/2009/09/09/infinitest-an-autotest-for-eclipse/</link>
		<comments>http://giordano.scalzo.biz/2009/09/09/infinitest-an-autotest-for-eclipse/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 17:00:07 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[infinitest]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://giordano.scalzo.biz/?p=70</guid>
		<description><![CDATA[In my experimental trips in Ruby world, other than the elegance of the language, the Bdd as default and the lot of new exciting things created by the community, a thing I liked a lot was autotest , a little gem that launches our testsuite when we change a source file.
It could seem a silly [...]]]></description>
			<content:encoded><![CDATA[<p>In my experimental trips in Ruby world, other than the elegance of the language, the Bdd as default and the lot of new exciting things created by the community, a thing I liked a lot was <a href="http://www.zenspider.com/ZSS/Products/ZenTest/" target="_blank">autotest</a> , a little gem that launches our testsuite when we change a source file.<br />
It could seem a silly utility, but I can assure it&#8217;s a really time saver and can take us in a high productive mental flow: I really missed it in Java world.</p>
<p>Of course, I&#8217;ve heard about <a href="http://www.threeriversinstitute.org/junitmax/subscribe.html" target="_blank">Junit Max</a>, the Kent Beck&#8217;s attempt to create a product, but my laziness delayed me to try it, until Kent got bored and dismiss the project <img src='http://giordano.scalzo.biz/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> .</p>
<p>Today while reading distractedly the Twitterverse, I bumped into <a href="http://infinitest.org" target="_blank">Infinitest</a>, that seems exactly what I was looking for.<br />
<a href="http://infinitest.org" target="_blank">Infinitest</a> isn&#8217;t open source, but for personal use it should be possible get a free of charge <a href="http://improvingworks.com/products/infinitest/for-individuals/" target="_blank">individual license</a>.</p>
<p>The installation is straightforward as usual, just add <code>http://update.improvingworks.com </code>to Eclipse&#8217;s software updates, and we are ready to start!</p>
<p><a href="http://infinitest.org" target="_blank">Infinitest</a> stay in the right bottom of Eclipse, waiting far some changes:</p>
<p><img class="aligncenter size-full wp-image-71" title="waiting for changes" src="http://giordano.scalzo.biz/wp-content/uploads/2009/09/waiting.png" alt="waiting for changes" width="441" height="43" /></p>
<p>When we save some file <a href="http://infinitest.org" target="_blank">Infinitest</a> starts and show the results of all test it founds in the project:</p>
<p><img class="aligncenter size-full wp-image-74" title="red test" src="http://giordano.scalzo.biz/wp-content/uploads/2009/09/red.png" alt="red test" width="507" height="199" /></p>
<p>A nice feature is the yellow bar when there is some error in the workspace and tests can&#8217;t run:</p>
<p><img class="aligncenter size-full wp-image-76" title="yellow bar" src="http://giordano.scalzo.biz/wp-content/uploads/2009/09/ytest.png" alt="yellow bar" width="716" height="359" /></p>
<p>That&#8217;s all!<br />
I have to try it more, but it seems very promising and useful.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/eclipse' rel='tag' target='_self'>eclipse</a>, <a class='technorati-link' href='http://technorati.com/tag/infinitest' rel='tag' target='_self'>infinitest</a>, <a class='technorati-link' href='http://technorati.com/tag/java' rel='tag' target='_self'>java</a>, <a class='technorati-link' href='http://technorati.com/tag/tdd' rel='tag' target='_self'>tdd</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/09/09/infinitest-an-autotest-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bdd with JBehave</title>
		<link>http://giordano.scalzo.biz/2009/09/04/bdd-with-jbehave/</link>
		<comments>http://giordano.scalzo.biz/2009/09/04/bdd-with-jbehave/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:50:20 +0000</pubDate>
		<dc:creator>giordano scalzo</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[jbehave]]></category>
		<category><![CDATA[kata]]></category>

		<guid isPermaLink="false">http://www.scalzo.biz/?p=32</guid>
		<description><![CDATA[Somebody defined Behaviour-Driven Development &#8220;TDD done right&#8221;; maybe is a bit too provocative as definition, but I think it&#8217;s the time to get my hands wet and give Bdd a chance.
JBehave is the first BDD&#8217;s framework, developed by the BDD&#8217;s inventor himself, Dan North, and still one of the more supported in Java community.
I choose [...]]]></description>
			<content:encoded><![CDATA[<p>Somebody defined <a href="http://behaviour-driven.org/" target="_blank">Behaviour-Driven Development</a> &#8220;TDD done right&#8221;; maybe is a bit too provocative as definition, but I think it&#8217;s the time to get my hands wet and give Bdd a chance.</p>
<p><a href="http://jbehave.org/" target="_blank">JBehave</a> is the first BDD&#8217;s framework, developed by the BDD&#8217;s inventor himself, <a href="http://dannorth.net/" target="_blank">Dan North</a>, and still one of the more supported in Java community.</p>
<p>I choose a simple kata to develop in Bdd-way, the StringTemplater kata, as saw in a <a href="http://www.coreyhaines.com/" target="_blank">Corey Haines</a>&#8216; <a href="http://blog.envylabs.com/2009/08/corey-haines-performance-kata/" target="_blank">video</a> and following this excellent <a href="http://www.shaafshah.com/2009/08/12/getting-started-with-jbehave-in-8-steps/" target="_blank">post</a>.</p>
<h3>JBehave on Eclipse: half an hour tutorial</h3>
<p>First of all, we should create a project under Eclipse and add JBehave <a href="http://jbehave.org/software/download/" target="_blank">jars</a>.</p>
<p>Then we should write the basic infrastructure: a textual file with the scenarios and two classes connecting our stories to JBehave.</p>
<p>By default the scenarios file should be without extension and in the same directory of classes, but, aiming to separate specs code and production code, I created a new source directory called <code>scenario</code>.</p>
<p>The scenarios file should have a meaningful name and the words should separated by underscores; in this example I called it <code>replace_tokens_in_string</code>.</p>
<p>At the beginning of the file, we can write the story we should implement: it isn&#8217;t mandatory, but it&#8217;s useful if we use specs to comunicate with the customers.<br />
Following we can write a first basic scenario:</p>
<pre class="brush: bash">Story: replace tokens in String
As a user
I would like replace token in a string with values
So that I can create templates for my configuration files

Scenario: replace empty string
Given I have a StringTemplater
When I ask to replace an emptystring
Then I should get an emptystring</pre>
<p>The story is just descriptive, but the scenario must be of the form of<br />
<code><strong>Given</strong> something<br />
<strong>When</strong> action<br />
<strong>Then</strong> check</code></p>
<p>Now we need create two java classes.<br />
The first one is JBehave wrapper to JUnit TestCase and its name should match the one of textual file converted in CamelCase: in our example should be <code>ReplaceTokensInString</code>.</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jbehave;

import org.jbehave.scenario.Scenario;

public class ReplaceTokensInString extends Scenario{
	  public ReplaceTokensInString() {
	        super(new ReplaceTokensInStringSteps());
	    }
}</pre>
<p>The second class, <code>ReplaceTokensInStringSteps</code>, implementing the steps of the scenario:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jbehave;

import org.jbehave.scenario.steps.Steps;

public class ReplaceTokensInStringSteps extends Steps {
}</pre>
<p>That&#8217;s it!<br />
As said before, JBehave is built over JUnit so we can run <code>ReplaceTokensInString</code> as Junit test obtaining a message from the engine:</p>
<pre class="brush: bash">Story: replace tokens in String
As a user
I would like replace token in a string with values
So that I can create templates for my configuration files

Scenario: replace empty string

Given I have a StringTemplater (PENDING)
When I ask to replace an emptystring (PENDING)
Then I should get an emptystring (PENDING)</pre>
<p><code>PENDING</code> means we have to build that step; so we do it with an empty implementation:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jbehave;

import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;
import org.jbehave.scenario.steps.Steps;

public class ReplaceTokensInStringSteps extends Steps {
	@Given("I have a StringTemplater")
	public void createStringTemplater() {
	}
	@When("I ask to replace an emptystring")
	public void replaceAnEmptystring() {
	}
	@Then("I should get an emptystring")
	public void shouldGetEmptyString() {
	}
}</pre>
<p>and when we run again the test, the <code>PENDING</code> messages should disappear.</p>
<p>This is the basic infrastructure, but, in my tiny experience was the most difficult part: once the empty scenario worked, implement the complete kata was quite straightforward.</p>
<p>This is my final scenarios file:</p>
<pre class="brush: java">Story: replace tokens in String
As a user
I would like replace token in a string with values
So that I can create templates for my configuration files

Scenario: replace empty string
Given I have a StringTemplater
When I ask to replace an emptystring
Then I should get an emptystring

Scenario: replace string without tokens
Given I have a StringTemplater
When I ask to replace 'this string'
Then I should get 'this string'

Scenario: replace string with a token
Given I have a StringTemplater
When I ask to replace 'Hello, $name' with [name : pippo]
Then I should get 'Hello, pippo'

Scenario: replace string with two tokens
Given I have a StringTemplater
When I ask to replace 'Hello, $name, how a $attitude day' with [name : pippo, attitude: wonderful]
Then I should get 'Hello, pippo, how a wonderful day'

Scenario: replace string with two adjacent tokens
Given I have a StringTemplater
When I ask to replace 'Hello, $adj$name' with [name : friend, adj: good]
Then I should get 'Hello, goodfriend'

Scenario: replace string with two tokens and only one value
Given I have a StringTemplater
When I ask to replace 'Hello, $name, how a $attitude day' with [name : pippo]
Then I should get 'Hello, pippo, how a  day'</pre>
<p>This my steps:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jbehave;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.jbehave.Ensure.ensureThat;

import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;
import org.jbehave.scenario.steps.Steps;

public class ReplaceTokensInStringSteps extends Steps {
	private StringTemplater templater;
	private String result;

	@Given("I have a StringTemplater")
	public void createStringTemplater() {
		templater = new StringTemplater();
	}

	@When("I ask to replace an emptystring")
	public void replaceAnEmptystring() {
		result = templater.replace("");
	}

	@Then("I should get an emptystring")
	public void shouldGetEmptyString() {
		ensureThat(result, is(equalTo("")));
	}

	@When("I ask to replace '$stringToReplace'")
	public void replaceStringWithoutTokens(String stringToReplace) {
		result = templater.replace(stringToReplace);
	}

	@Then("I should get '$expected'")
	public void checkStringResult(String expected) {
		ensureThat(result, is(equalTo(expected)));
	}

	@When("I ask to replace '$stringToReplace' with [$tokens]")
	public void replaceStringWithTokens(String stringToReplace, String tokens) {
		result = templater. replace(stringToReplace,tokens);
	}

}</pre>
<p>and, last but not least, <code>StringTemplater</code> class:</p>
<pre class="brush: java">package biz.scalzo.kata.stringtemplater.jbehave;

import java.util.HashMap;
import java.util.Map.Entry;

public class StringTemplater {

	public String replace(String originaleString) {
		return replace(originaleString, "");
	}

	public String replace(String stringToReplace, String tokensAsString) {
		HashMap tokensMap = splitTokens(tokensAsString);
		return removeKeywordWithoutValue(replaceKeywords(stringToReplace,
				tokensMap));
	}

	private String removeKeywordWithoutValue(String replaceKeywords) {
		return replaceKeywords.replaceAll("\\$\\w+", "");
	}

	private String replaceKeywords(String initialValue,
			HashMap tokensMap) {
		String result = initialValue;
		for (Entry entry : tokensMap.entrySet()) {
			result = result
					.replaceAll("\\$" + entry.getKey(), entry.getValue());
		}
		return result;
	}

	private HashMap splitTokens(String tokensAsString) {
		String[] pairs = splitPairs(tokensAsString);

		HashMap result = new HashMap();
		for (String pair : pairs) {
			String[] tokens = pair.split(":");
			if (tokens.length &gt; 1) {
				result.put(tokens[0].trim(), tokens[1].trim());
			}
		}
		return result;
	}

	private String[] splitPairs(String tokensAsString) {
		return tokensAsString.split(",");
	}
}</pre>
<h3>Conclusions</h3>
<p>This is my first impact with Bdd in Java, I liked and I think it&#8217;s very promising.<br />
Neverthless, I still don&#8217;t know if it is something I can do in day by day work or just a proof of concept: Jbehave is quite verbose and the stories are high level specifications, so we need to write a lot of boilerplate code to specify a class.</p>
<p>In my trip in Bdd-land, next steps will be give other Bdd engines a try, starting with ones written in high level languages as <a href="http://www.easyb.org/" target="_blank">easyb</a> or <a href="http://www.artima.com/scalatest/" target="_blank">scalatest</a>.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bdd' rel='tag' target='_self'>bdd</a>, <a class='technorati-link' href='http://technorati.com/tag/eclipse' rel='tag' target='_self'>eclipse</a>, <a class='technorati-link' href='http://technorati.com/tag/java' rel='tag' target='_self'>java</a>, <a class='technorati-link' href='http://technorati.com/tag/jbehave' rel='tag' target='_self'>jbehave</a>, <a class='technorati-link' href='http://technorati.com/tag/kata' rel='tag' target='_self'>kata</a>, <a class='technorati-link' href='http://technorati.com/tag/tutorial' rel='tag' target='_self'>tutorial</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://giordano.scalzo.biz/2009/09/04/bdd-with-jbehave/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
