I’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 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 “Login” feature might consist of the scenarios “Login with username/password” and “Login with OpenID”):
Given some initial context (the givens),
When an event occurs,
Then ensure some outcomes.
(from http://dannorth.net/introducing-bdd)
“Given” defines the preconditions, “When” defines what happens, and “Then” defines the result of the scenario. Or in other words: “Given” describes the start state, and “When” the steps necessary to reach the accepting state (= “Then”).
A simple example of a “Publish new article” scenario might look like:
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
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’s something for another post…

Hi Daniel thanks for the article. The concept looks very interesting..
@Krish: You are welcome :)
In one of my past project i have used cucumber and webrat to test CakePHP apps with great success, given everything is over HTTP.
Here is got some instruction how to set it up..
http://jystewart.net/process/2008/11/testing-php-apps-with-ruby-tools/
@taylor: Thanks for the link, and yes, using cucumber and webrat can be an option for testing your PHP applications.
Hi there cakebaker, I use cucumber webrat and Rspec for acceptance testing my code, but I can’t make it work with “radio_button”. I have done many tests with other controls and webrat works nice but when I try to choose one item from a list of radio_buttons webrat does not find the item, nor by it’s id, label or name.
@Boris: Hm, I just did a quick test and it seems to work here and the element is found either by id or its label. Do you use the most recent version of webrat? (I’m using webrat 0.4.4)
Hope that helps!
Yeah I use version 0.4.4, I’ll double check what it is wrong
Man I know what I was Doing wrong, I should have created the Items that fill the radio button before visiting the action. Thanx, keep up the good work. Check the post. I haven’t tred to use factories in Webrat Yet!.
http://railsforum.com/viewtopic.php?id=32990
@Boris: Good to hear you found a solution :)