Cucumber and Wowspec

Posted by caike on March 09, 2009

It was back in September of last year that I first heard about RSpec. The possibility of bringing requirements in the form of User Stories straight to code amazed me and I quickly started playing around with its Story Runner.

In order to try out RSpec SR, I came up with a few lines of code and named it wowspec, in an attempt to describe and code some (very) small part of the behavior in World of Warcraft. One simple feature, that is.

But why World of Warcraft ?

Well, because it is fun and that is what programming should be all about.

To my surprise, a few months later during Rails Summit Latin America, David Chelimsky announced that the new Cucumber project would replace RSpec SR. Since then, I have been reading about Cucumber but never really tried out.

This week I decided to give Cucumber a try by rewriting my little wowspec example. I chose to keep the old name because I couldn´t come up with a better one related to Cucumber.

The project itself (check it out on my github) is really just an excuse to practice TDD (or BDD, if you wish), Ruby programming and also Cucumber. It is one single Cucumber feature, which describes a character being attacked in three different scenarios.

Scenario: Character in idle mode gets attacked
Given a character in idle mode
When he gets attacked with a sword
Then he should be in combat mode

Scenario: Character in combat mode gets attacked again
Given a character in combat mode
When he gets attacked with a sword
Then he should be in critical mode

Scenario: Character in idle mode gets fooled
Given a character in idle mode
When he gets attacked with a banana
Then he should be in idle mode

I have been using this wowspec example for introducing agile best practices to people new to unit testing and TDD, either using Java (JUnit or JBehave) or Ruby and the results have been great!

Leaving the “enterprisey” world every now and then and looking for inspiration from other sources brings joy back to programming, I believe. I strongly encourage everyone to do the same. Games, sports, nature, space, sci-fi, whatever.

Come up with something you enjoy and bring it to life through code. You will be excercising your coding skills, uncovering your own best practices and enhancing your software craftsmanship.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments

Anti-Spam Protection by WP-SpamFree