<?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>cakebaker &#187; bdd</title>
	<atom:link href="http://cakebaker.42dh.com/tags/bdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>let()&#8217;s write slightly cleaner specs</title>
		<link>http://cakebaker.42dh.com/2010/04/02/lets-write-slightly-cleaner-specs/</link>
		<comments>http://cakebaker.42dh.com/2010/04/02/lets-write-slightly-cleaner-specs/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 09:08:23 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1345</guid>
		<description><![CDATA[When writing specs for your code, you often have to do some initialization. With RSpec I do this initialization in a &#8220;before&#8221; block as shown in the following example: describe BlogPost do before do @blog_post = BlogPost.create :title =&#62; 'Hello' end it "does something" do @blog_post.should ... end it "does something else" do @blog_post.should ... [...]]]></description>
			<content:encoded><![CDATA[<p>When writing specs for your code, you often have to do some initialization. With <a href="http://rspec.info">RSpec</a> I do this initialization in a &#8220;before&#8221; block as shown in the following example:</p>
<pre>
<code>describe BlogPost do
  before do
    @blog_post = BlogPost.create :title =&gt; 'Hello'
  end

  it "does something" do
    @blog_post.should ...
  end

  it "does something else" do
    @blog_post.should ...
  end
end</code>
</pre>
<p>However, recently I stumbled upon a cleaner approach in a <a href="http://pure-rspec-scotruby.heroku.com/">presentation</a> (from which I borrowed the examples in this article) by <a href="http://twitter.com/L4rk">Jon Larkowski</a> that makes use of RSpec&#8217;s let() method. With this approach, the example from above looks like:</p>
<pre>
<code>describe BlogPost do
  let(:blog_post) { BlogPost.create :title =&gt; 'Hello' }

  it "does something" do
    blog_post.should ...
  end

  it "does something else" do
    blog_post.should ...
  end
end</code>
</pre>
<p>At first this looked quite magic to me and I had no clue how it worked. Though a look at the source of the let() method reveals the magic (the code should be self-explanatory, or else please leave a comment):</p>
<pre>
<code>def let(name, &amp;block)
  define_method name do
    @assignments ||= {}
    @assignments[name] ||= instance_eval(&amp;block)
  end
end</code>
</pre>
<p>Happy RSpecing!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2010/04/02/lets-write-slightly-cleaner-specs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Given-When-Then</title>
		<link>http://cakebaker.42dh.com/2009/05/28/given-when-then/</link>
		<comments>http://cakebaker.42dh.com/2009/05/28/given-when-then/#comments</comments>
		<pubDate>Thu, 28 May 2009 13:15:13 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[bdd]]></category>
		<category><![CDATA[requirements]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1191</guid>
		<description><![CDATA[I&#8217;m currently doing my first steps with BDD (Behavior Driven Development) and Cucumber, a Ruby tool for doing BDD. What I like about BDD is the simple, but powerful concept of Given-When-Then for specifying scenarios. It is a concept you can also use without doing BDD to specify the requirements of your application. It simply [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently doing my first steps with <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD (Behavior Driven Development)</a> and <a href="http://cukes.info/">Cucumber</a>, a Ruby tool for doing BDD. </p>
<p>What I like about BDD is the simple, but powerful concept of Given-When-Then for specifying scenarios. It is a concept you can also use without doing BDD to specify the requirements of your application. </p>
<p>It simply defines the structure of how you write down the requirements in the form of scenarios (as a sidenote: in BDD, a scenario belongs to a feature. For example, a &#8220;Login&#8221; feature might consist of the scenarios &#8220;Login with username/password&#8221; and &#8220;Login with OpenID&#8221;):</p>
<pre>
<code>Given some initial context (the givens),
When an event occurs,
Then ensure some outcomes.</code>
</pre>
<p>(from <a href="http://dannorth.net/introducing-bdd">http://dannorth.net/introducing-bdd</a>)</p>
<p>&#8220;Given&#8221; defines the preconditions, &#8220;When&#8221; defines what happens, and &#8220;Then&#8221; defines the result of the scenario. Or in other words: &#8220;Given&#8221; describes the start state, and &#8220;When&#8221; the steps necessary to reach the accepting state (= &#8220;Then&#8221;). </p>
<p>A simple example of a &#8220;Publish new article&#8221; scenario might look like:</p>
<pre>
<code>Given I am logged in
When I write an article with the title "My article"
And I publish the article
Then I should see the message "Article published"
And the article "My article" should appear on the homepage</code>
</pre>
<p>The simplicity of this format makes it easy to discuss the requirements of your application. And thanks to tools like Cucumber you can even make such specifications executable, but that&#8217;s something for another post&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2009/05/28/given-when-then/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

