Toll free (US) : +1 (888) 838-3532 | NYC: +1 (646) 491-6866

What is Cucumber?

Cucumber is used for Behavior Driven Development. Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.

Cucumber works with Ruby on Rails, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages. Cucumber also supports more succinct tests in tables – similar to what FIT does.

Install cucumber for Rails 3:

Install Cucumber, Rspec-rails and capybara gem

  • Cucumber is a behavior driven development (BDD) framework in particular good for integration and functional tests

  • RSpec is a behavior driven development (BDD) framework for low-level testing in the Ruby language
  • database_cleaner performs DB cleanup in testing
  • capybara simulating a browser, automating a browser or setting expectations using the matchers.

Using Cucumber to test rails 3 application:

1. Create a new Rails application store

$rails new store -d mysql

2. Edit the Gemfile

Include the Cucumber gems in a Rails 3 application

4. Install the cucumber skeleton files to a Rails 3 application.

The cucumber-rails generator creates the directories:

features/step_definitions

features/support

The cucumber-rails generator creates the files:

config/cucumber.yml

features/support/env.rb

lib/tasks/cucumber.rake

script/cucumber

7. Run the Cucumber features

$rake cucumber

Create cucumber features:
  • Create a Cucumber Feature for RoR 3 application testing

$vi features/manage_store.feature

  • Cucumber Feature is the business user testing specification written in plain English with a specific format

Feature Format

Implement the testing steps and Ruby on Rails model code for Cucumber on Rails :

  • Create Cucumber step definitions

$vi features/step_definitions/order_steps.rb

  • Cucumber uses regular expression to match string and pass it to the step definitions
  • Run Cucumber

An example might be the ability to manage companies:


Contact RailsCarma | Global Rails Company