We are a software consultancy based in Berlin, Germany. We deliver
high quality web apps in short timespans.

Upstream Agile GmbH Logo

cucumber - next generation rspec story runner (updated)

August 26, 2008 by alex

yesterday while skimming through my Twitter timeline I stumbled across aslak hellesoy’s cucumber. cucumber is a rewrite of the rspec story runner, allowing you to write user stories in plain text and make them executable by adding a bunch of ruby magic.

the features of both - story runner and cucumber - are basically the same. cucumber just gets rid of all these little glitches that disturb your work flow when working with story runner and adds that little bit of polish that makes the difference. but see for yourself:

first of all it replaces those 5 lines of infrastructure code you needed for every story with a set of conventions. (require helper, require and run story text file, load additional steps files). stories are now called features and have a corresponding .feature file extension. the steps are located in *steps.rb files as before but don’t require any more steps_for or with_steps calls.

also improved is running stories: there’s a script called cucumber that can run a feature directly by calling cucumber my_feature.feature and there’s a rake task (rake features) to run all of them - say hello to my build server.

the wording has also changed. instead of "as a <role> I want to be able to <feature> so that <outcome>" we now have "in order to <outcome> a <role> should be able to <feature>. this might seem like a minor twist but I think it’s an important one. now you (your customer) have to think about which outcome you want even before you talk about features. if you can’t come up with a sensible outcome don’t even finish that sentence. hope that will end the "oh we still need a 'so that' clause for that feature" discussions.

adding before and after hooks has now become easier. instead of adding listeners you now just create a Before do .. end or After do .. end block.

another addition is the inclusion of a couple of webrat helpers. some people might argue that this something an application neutral framework like rspec (after all you can test anything with rspec, not just web apps) shouldn’t care about, but honestly, i think at least 80% of the people using rspec use it for web apps, so helping these people write better specs should be worth it. and webrat is definitely a big step in the right direction if you want to be testing specing webapps. if you don’t need it just delete the common_webrat.rb file. if you do use rspec for web testing take a look at that file. with this you can start test driving your web app without writing any ruby code by clicking links and submitting forms.

  When I go to "/"
  And I follow "New Entry"
  And I fill in "my first blog entry" for "Body"
  And I press "Submit"
  Then I should see "Blog entry was saved"

Simple as that. Your (first?) cucumber feature spec. If you want more source code take a closer look at the examples on github.

Last but not least the output has been enhanced. By default all successful steps are now in green, pending steps in yellow and failures in red - and the backtrace can be found next to that failed step instead of at the end as it used to be.

What’s still missing is a decent TextMate bundle:

Unfortunately I’m really busy these days so I probably won’t be the one making this feature shine green. Hopefully someone else will soon.

Update There is a TextMate bundle now an it’s working. It highlights your feature’s syntax and lets you run a single scenario from within TextMate. Great. Get it from GitHub while it’s hot. (thanks Paul)

Hello Explorer!

You’ve found our very old Website Archive (2007-2012). It’s a bit out of date, but we love looking back at how it all started - and how far we’ve come since then! We’re now fully focused on building our coworking management product, Cobot.

Take a look →