Cucumber

Cucumber is a tool that can execute documentation written in plain text. Cucumber targets non technical domain experts as well as programmers and QA people. Cucumber itself is written in Ruby, but it can be used to “test” code written in Ruby, Java (or web applications written in any language). When IronRuby matures it can be used to “test” .NET code too.

While Cucumber can be thought of as a “testing” tool, most people use it to support BDD, so the “tests” are typically the first thing that gets written, and the production code is then written outside-in, to make the test pass.

Installation

After you have installed Ruby or JRuby – install Cucumber with the following commands:

Ruby:

gem sources --add http://gems.github.com/ 
gem install aslakhellesoy-cucumber

JRuby:

jruby -S gem sources --add http://gems.github.com/ 
jruby -S gem install aslakhellesoy-cucumber

Getting started

I haven’t written a tutorial yet. Take a look at the examples. Each example directory has a Rakefile, and you can run the features with

rake features

Background and Credits

Cucumber is a rewrite of RSpec’s “Story runner”, which was originally written by Dan North. Dan’s original implementation required that stories be written in Ruby. Shortly after, David Chelimsky added plain text support.

This brought executable stories a little closer to non-technical users, which is one of the target audiences for this kind of tool.

However, the RSpec Story runner has several shortcomings which is rather common for tools that move into new territory. Some of the biggest problems with it are:

  • Hard to get started with. A special “all.rb” file must be written before it can be used.
  • No out of the box Rake support, which puts a lot of people off.
  • No i18n, so if you want to write stories in a different language than English you’re out of luck.
  • Poor error reporting. No way to know on what line a plain text story failed during execution or parsing.
  • Limited colouring of output.
  • No simple way to execute only one scenario.
  • No command line tool to run stories.

While all of this could have been fixed in the existing codebase, I figured it would be easier to do a rewrite from scratch. I also had some ideas for extensions of the story grammar, so I decided to use Treetop and base it on a proper grammar

Cucumber addresses all of the shortcomings of RSpec’s Story runner. If the community likes it, we’ll consider phasing out the RSpec story runner.

The term “Feature” has been adopted in favour of “Story” because I believe it is a more appropriate term. A feature’s scenarios typically increases over time – fed by several user stories.