cucumber – next generation rspec story runner (updated)
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)
Tags: bdd, cucumber, rspec, story-runner




September 24th, 2008 at 23:22
Ben Mabey is working on a TextMate bundle.
http://github.com/bmabey/cucumber-tmbundle/tree/master
September 25th, 2008 at 09:10
thanks. the last time i checked it only had a readme. that has obviously changed.will install now.
October 1st, 2008 at 10:14
[...] Cucumber – Next Generation RSpec Story Runner – Some of the basics. [...]
February 11th, 2009 at 13:10
Give the complete code for complete application like banking application
there are lots of scenarios like
1. Depositing money
2. Withdrawal
so give complete code for each and every scenario in proper format so others can easily understand.and present in good format like ppt or use animation .i.e some sort of graphics
February 11th, 2009 at 17:33
@mahesh sorry i’m not sure what you are talking about. cucumber doesn’t have to do anything with powerpoint or animations
August 12th, 2009 at 13:02
graphics means tags that are available on screen.
August 31st, 2010 at 18:12
super witryna. zapraszam zarowno do moja witryne.