cucumber-ruby Documentation

Cucumber for Ruby. It's amazing!

5,211 stars Ruby Ruby 1 file ยท ~15,054 tokens #cucumber#polyglot-release#ruby#tidelift
RAW Doc

1. Project Overview & Quickstart (cucumber/cucumber-ruby)

File: README.md

Cucumber

Cucumber is a tool for running automated tests written in plain language. Because they're
written in plain language, they can be read by anyone on your team. Because they can be
read by anyone, you can use them to help improve communication, collaboration and trust on
your team.

This is the Ruby implementation of Cucumber. Cucumber is also available for JavaScript,
Java, and a lot of other languages. You can find a list of implementations here: https://cucumber.io/docs/installation/.

See CONTRIBUTING.md for info on contributing to Cucumber (issues, PRs, etc.).

Everyone interacting in this codebase and issue tracker is expected to follow the
Cucumber code of conduct.

Installation

Cucumber for Ruby is a Ruby gem. Install it as you would install any gem: add
cucumber to your Gemfile:

text
gem 'cucumber'

then install it:

text
$ bundle

or install the gem directly:

text
$ gem install cucumber

Later in this document, bundler is considered being used so all commands are using
bundle exec. If this is not the case for you, execute cucumber directly, without
bundle exec.

Supported platforms

  • Ruby 4.0
  • Ruby 3.4
  • Ruby 3.3
  • Ruby 3.2
  • TruffleRuby 24.0.0+
  • JRuby 10.0+ (with some limitations)

Ruby on Rails

Using Ruby on Rails? You can use cucumber-rails to bring Cucumber into your Rails project.

Usage

Initialization

If you need to, initialize your features directory with

text
$ bundle exec cucumber --init

This will create the following directories and files if they do not exist already:

text
features
โ”œโ”€โ”€ step_definitions
โ””โ”€โ”€ support
    โ””โ”€โ”€ env.rb

Create your specification

Create a file named rule.feature in the features directory with:

gherkin
# features/rule.feature

Feature: Rule Sample

  Rule: This is a rule

    Example: A passing example
      Given this will pass
      When I do an action
      Then some results should be there

    Example: A failing example
      Given this will fail
      When I do an action
      Then some results should be there

Automate your specification

And a file named rule_steps.rb in features/step_definitions with:

ruby
# features/step_definitions/steps.rb

Given('this will pass') do
  @this_will_pass = true
end

Given('this will fail') do
  @this_will_pass = false
end

When('I do an action') do
  :no_op
end

Then("some results should be there") do
  expect(@this_will_pass).to be true
end

Run Cucumber

text
$ bundle exec cucumber

To execute a single feature file:

text
$ bundle exec cucumber features/rule.feature

To execute a single example, indicates the line of the name of the example:

text
$ bundle exec cucumber features/rule.feature:5

To summarize the results on the standard output, and generate a HTML report on disk:

text
$ bundle exec cucumber --format summary --format html --out report.html

For more command line options

text
$ bundle exec cucumber --help

You can also find documentation on the command line possibilities in features/docs/cli.

Documentation and support

Copyright (c) Cucumber and Contributors. See LICENSE for details.


File: docs/jruby-limitations.md

Cucumber and JRuby limitations

cucumber can be executed on JRuby (tested with 10.0), although some of the features
are not available on this platform.

Defining steps with native languages

There are currently three languages (Russian, Ukrainian and Uzbek) for which the step definition
can not be written in native language.

That means, for example, that you can not write the following code:

ruby
ะ”ะพะฟัƒัั‚ะธะผ('ั ะฒะฒะพะถัƒ ั‡ะธัะปะพ {int}') do |ั‡ะธัะปะพ|
  calc.push(ั‡ะธัะปะพ)
end

Instead, you have to write (NB: both the gherkin term and the block variable(s) are in English):

ruby
Given('ั ะฒะฒะพะถัƒ ั‡ะธัะปะพ {int}') do |number|
  calc.push(number)
end

Of course, you can still write your feature files in a native language, for example, the following
feature file can be executed on JRuby:

gherkin
# language: ru
ะคัƒะฝะบั†ะธะพะฝะฐะป: ะกะปะพะถะตะฝะธะต ั‡ะธัะตะป
  ะงั‚ะพะฑั‹ ะฝะต ัะบะปะฐะดั‹ะฒะฐั‚ัŒ ะฒ ัƒะผะต
  ะ’ัะต, ัƒ ะบะพะณะพ ั ัั‚ะธะผ ั‚ัƒะณะพ
  ะฅะพั‚ัั‚ ะฐะฒั‚ะพะผะฐั‚ะธั‡ะตัะบะพะต ัะปะพะถะตะฝะธะต ั†ะตะปั‹ั… ั‡ะธัะตะป

  ะกั†ะตะฝะฐั€ะธะน: ะกะปะพะถะตะฝะธะต ะดะฒัƒั… ั†ะตะปั‹ั… ั‡ะธัะตะป
    ะ”ะพะฟัƒัั‚ะธะผ ั ะฒะฒะพะถัƒ ั‡ะธัะปะพ 50
    ะ˜ ะทะฐั‚ะตะผ ะฒะฒะพะถัƒ ั‡ะธัะปะพ 70
    ะ•ัะปะธ ั ะฝะฐะถะธะผะฐัŽ "+"
    ะขะพ ั€ะตะทัƒะปัŒั‚ะฐั‚ะพะผ ะดะพะปะถะฝะพ ะฑั‹ั‚ัŒ ั‡ะธัะปะพ 120

In our CI system these languages are tested using the anglicised step definitions


File: docs/vscode-example-launch-configuration.md

Pre-requisites

Ruby Extension

Install and configure the ruby extension

Use `debase` and `ruby-debug-ide` gems locally

Make sure to use a Gemfile.local file with debase and ruby-debug-ide gems.

ruby
# Include the regular Gemfile
eval File.read('Gemfile')

group :development do
  gem 'debase', require: false
  gem 'ruby-debug-ide', require: false
end

Execute bundle config set --local gemfile Gemfile.local to use it per default,
then bundle install.

Sample launch.json

The following launch.json - to be placed in the .vscode folder - allows to use
VSCode debugging features like breakpoints and watches.

text
/* Detailed source-code truncated for AI context efficiency. */

File: features/docs/writing_support_code/hooks/README.md

Cucumber Hooks

Cucumber proposes several hooks to let you specify some code to be executed at
different stages of test execution, like before or after the execution of a
scenario.

Hooks are part of your support code.

They are executed in the following order:

You can define as many hooks as you want. If you have several hooks of the same
types - for example, several BeforeAll hooks - they will be all executed once.

Multiple hooks of the same type are executed in the order that they were defined.
If you wish to control this order, use manual requires in env.rb - This file is
loaded first - or migrate them all to one hooks.rb file.

Finaly, all hooks can be given a name to improve reporting and help debugging.

Note: Hooks names are only reported when using the message and the html formatters.

InstallPlugin

InstallPlugin hook is dedicated to using plugins and is meant to
extend Cucumber. For example, it allows to dynamically change the configuration
before the execution of tests or to add some code that could impact the execution itself.

In addition to the configuration, InstallPlugin has access to some of the Cucumber
internals through a RegistryWrapper, defined in
lib/cucumber/glue/registry_wrapper.rb.

ruby
InstallPlugin do |configuration, registry|
  # configuration is an instance of Cucumber::Configuration defined in
  # lib/cucumber/configuration.rb
  #
  # registry is an instance of Cucumber::Glue::RegistryWrapper defined in
  # lib/cucumber/glue/registry_wrapper.rb
end

# named hook:

InstallPlugin(name: 'Installation of a plugin') do |configuration, registry|
  # The name is optional
end

You can see an example in the Cucumber Wire plugin.

BeforeAll and AfterAll

BeforeAll is executed once before the execution of the first scenario. AfterAll
is executed once after the execution of the last scenario.

These two types of hooks have no parameters. Their purpose is to set-up and/or clean-up
your environment not related to Cucumber, like a database or a browser.

ruby
BeforeAll do
  # snip
end

AfterAll do
  # snip
end

# Named hooks:

BeforeAll(name: 'Name of the hook') do
  # snip
end

AfterAll(name: 'Name of the hook') do
  # snip
end

Around

Note: Around is a legacy hook and its usage is discouraged in favor of
Before and After hooks.

Around is a special hook which allows you to have a block syntax. Its original
purpose was to support some databases with only block syntax for transactions.

ruby
Around do |scenario, block|
  SomeDatabase::begin_transaction do # this is just for illustration
    block.call
  end
end

# with a name:

Around(name: 'Name of the hook') do |scenario, block|
  # snip
end

Before and After

Before is executed before each test case. After is executed after each test case.
They both have the test case being executed as a parameter. Within the After hook,
the status of the test case is also available.

ruby
Before do |test_case|
  log test_case.name
end

After do |test_case|
  log test_case.failed?
  log test_case.status
end

# With names:

Before(name: 'Name of the hook') do |test_case|
  # snip
end

After(name: 'Name of the hook') do |test_case|
  # snip
end

AfterStep

AfterStep is executed after each step of a test. If steps are not executed due
to a previous failure, AfterStep won't be executed either.

ruby
AfterStep do |result, test_step|
  log test_step.inspect # test_step is a Cucumber::Core::Test::Step
  log result.inspect # result is a Cucumber::Core::Test::Result
end

# with a name:

AfterStep(name: 'Named hook') do |result, test_step|
  # snip
end

File: features/docs/README.md

Cucumber for Ruby

Cucumber is a tool for running automated tests written in plain language. Because they're
written in plain language, they can be read by anyone on your team. Because they can be
read by anyone, you can use them to help improve communication, collaboration and trust on
your team.

Code of Conduct

Everyone interacting in this codebase and issue tracker is expected to follow the Cucumber code of conduct.

Copyright (c) Cucumber Ltd. and Contributors. See LICENSE for details.

2. Official Technical Reference & Guides (cucumber/docs)

File: README.md

Cucumber Documentation

๐Ÿšจ This repository is archived. the Cucumber documentation is now at https://github.com/cucumber/website. ๐Ÿšจ

Contributing Content

For small edits, the recommended way to contribute is via GitHub.
Each page in the documentation will have an Edit link for this purpose.

Working locally

For bigger modifications, the recommended workflow is to edit the documentation
locally on your machine, and seeing the results in a web browser.

This involves getting the source code and building the documentation yourself.

Get the source code

text
git clone https://github.com/cucumber/docs
cd docs

View the site

The website is built with several tools that are distributed as a Docker image.

Install Docker if you don't already have
it on your machine.

Build and serve the website:

text
./docker_shell.sh

Open a browser:

text
http://localhost:1313

Changes to the contents will be automatically updated in the browser.

Try editing one of the pages under content and see for yourself!

When you are done editing, build the site and check links:

text
./docker_shell.sh make clean
./docker_shell.sh make
./docker_shell.sh make htmlproofer

By default, external links are only checked in CI (because it takes a while).
To check external links locally:

text
CI=true ./docker_shell.sh make htmlproofer

Links that are broken should be removed or replaced, even if they are only
temporarily broken. The reason for this is that broken links negatively affect
search engine rankings.

Modify theme

See the theme README

Architecture

The site is built with Hugo, a fast static site generator.

We have a custom-built theme for the site in themes/cucumber-hugo. This theme
is based on Bulma - a lightweight CSS framework.

The online site is rebuild automatically whenever the git repository receives
new commits, either via a git push, or by modifying contents in the CMS.

The Netlify CMS saves contents straight to GitHub
using the GitHub API.

Continuous Deployment

GitHub will notify Netlify for every git push thanks to a webhook.

Netlify will then build the site and
deploy it if the build is successful.

The build will check for broken links and other problems. Internal and external links are checked by HTMLProofer.
Occasionally, the build will fail due to external links being unavailable or giving a timeout. When that happens, please check if these external links are available and if so, 'Retry build' on Netlify.

You can discuss the documentation in the Community Discord.


File: content/_todo/step-reuse.md


source: https://github.com/cucumber/cucumber/wiki/Step-Definitions/ source: https://github.com/cucumber/cucumber/wiki/Hooks/ source: https://github.com/cucumber/cucumber/wiki/Tags/ title: Cucumber Reference

Reusable step definitions

TODO: Describe how to use output parameters to make step definitions reusable

Reusable helper methods

TODO: Describe how to extract helper methods that can be used from steps


File: content/docs/tools/_index.md


title: Tools subtitle: Simplify your work with Cucumber power tools weight: 1180 menu: main iconClass: far fa-tools


File: content/docs/tools/general.md


title: Tools subtitle: "Editors, IDEs and build tools" weight: 1000

Using Cucumber in your project is more manageable with the right tools.

Editors

Most popular text editors support Gherkin syntax highlighting.

Some IDEs also have advanced support for Cucumber, such as running Cucumber
from within the IDE, displaying results, navigating between Gherkin steps and
step definitions and so on.

Atom

Atom is a text editor for macOS, Windows or Linux.

It offers several packages you can use with Cucumber.

TextMate

TextMate is a text editor for macOS.
See the Cucumber.tmbundle documentation.

Visual Studio Code

Visual Studio Code is a code editor for Windows, Linux, or macOS.

You can use it with a Cucumber (Gherkin) plugin.

Nova

Nova is a text editor for macOS.

See the Cucumber extension for Gherkin language support.

IDEs

Build Tools

You can run Cucumber using build tools, rather than from the command line.


File: content/docs/tools/java.md


title: Java Tools weight: 1100

This page describes tools commonly used with Java.

IDEs

IntelliJ IDEA

You can find more information on using Cucumber with IntelliJ IDEA in the IntelliJ IDEA Cucumber help pages

Eclipse

Build tools

The most widely used build tools for Java are Maven and Gradle.

Maven

To run Cucumber with Maven, make sure that:

  • Maven is installed
  • The environment variable MAVEN_HOME is correctly configured
  • The IDE is configured with the latest Maven installation

Clone the cucumber-java-skeleton to get started.

Gradle

To run Cucumber with Gradle, make sure that:

  • Gradle is installed
  • The environment variable GRADLE_HOME is correctly configured
  • The IDE is configured with the latest Gradle installation

Clone the cucumber-java-skeleton to get started.


File: content/docs/tools/javascript.md


title: JavaScript Tools weight: 1200

This page describes tools commonly used with JavaScript.

Build tools

The most widely used build tools for JavaScript are npm and Yarn.

npm

To use Cucumber with npm, make sure that:

  • npm is installed

Cucumber.js is available as an npm module.

Add cucumber as a development dependency:

shell
# NPM
npm install --save-dev @cucumber/cucumber

Yarn

To run Cucumber with Yarn, make sure that:

  • Yarn is installed

Add cucumber as a development dependency:

shell
# Yarn
yarn add --dev @cucumber/cucumber


People have written tools on top of Cucumber. These are the known third-party tools that work together with Cucumber:

Tool Description
Aruba Generic Step Definitions for command-line programs
AssertThat BDD & Test Management in Jira Combines feature/scenario management as well as built in test automation reporting in Jira. Website AssertThat
Backyard Name the models in your Cucumbers with ease
BDD Generator Generates random BDD scenarios in Gherkin format for testing purposes. By @DavertMik
Bermuda Capybara Step library for jQuery UI widgets
Capybara Webrat alternative which aims to support all browser simulators
Clearance Rails Authentication System with Cucumber Feature generator
Cluecumber Maven plugin for clear and concise Cucumber reporting.
Courgette Browse your cucumber features from within your Rails app with Courgette, a Rails engine.
cql A query language for Cucumber features
crb An irb console for Cucumber world. (crb = cucumber + irb)
Cucable Maven plugin that simplifies running Cucumber Scenarios in parallel.
Cucapp Cucumber integration with Cappuccino.
Cucover Coverage-aware lazy / selective Cucumber Feature runnner
Cucumber-cpp Cucumber for C
Cucumber.el Emacs mode for editing Cucumber plain text stories.
Cucumber Factory Create Rails model records without writing Step Definitions.
Cucumber Forge Generate static Cucumber reports using the Electron app or build your own integration with the NPM library.
Cucumber Growler Growl notifications for Cucumber.
Cucumber Nagios Web site monitoring with Cucumber and Nagios
Cucumber REST Gherkin library for Spring Library with predefined Gherkin sentences for testing REST APIs with Spring
cucumber-runner A Gradle Cucumber-JVM runner, it may simplify running Cucumber steps in parallel
cucumber-rust An implementation of the Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
Cucumber Scaffold Scaffolding gem for Cucumber Features
CucumberTFS Converts Team Foundation Server (TFS) Scenarios into Cucumber Scenarios in a single Feature file.
Cucumber TM Bundle Feature syntax highlighting and other useful commands for TextMate
Clucumber Support for writing Cucumber Step Definitions in Common LISP, testing Common LISP code.
cuke_cataloger Add unique identifiers to every test case in your suite
cuke_commander Dynamically generate Cucumber command lines
cuke_linter Linting tool for '.feature' files
cuke_modeler Abstraction layer that sits on top of gherkin as a stable base upon which to build other tooling
cuke_slicer Breaks a Cucumber suite into the most granularly executable pieces for better parallelization
Cuke4AS3 Actionscript
Cuke4Nuke Support for writing Cucumber Step Definitions in .NET.
Cuke4Lua Wire protocol implementation for Lua
Cuke4PHP Support for writing Cucumber Step Definitions in PHP, testing PHP code.
Cuke4Vs Syntax highlighting, intellisense and other editing support for Feature files in Visual Studio 2008.
Cukedoctor Enables Asciidoc markup on Cucumber features for creating readable living documentation.
Cuki Pull Cucumber Features from a Confluence wiki into Feature files
Culerity Integrates Cucumber and Celerity to test Javascript in webapps.
daml-cucumber Native cucumber testing for daml smart contracts.
DatabaseCleaner Different strategies for keeping your DB clean to ensure a clean state. Has Cucumber support out of the box.
Eclipse plugin Eclipse plugin for Cucumber
ecucumber An open source port of Cucumber for Erlang
Ecukes Emacs package that makes it possible to write Cucumber like tests for your Emacs packages
egherkin An Erlang library for parsing Gherkin documents
EmailSpec Collection of RSpec matchers and Cucumber Steps for testing email in a Rails app
fbrp Sample Rails app of Cucumber showing how to use with restful-authentication.
features2 features2 is a simple script that creates HTML and PDF based documentation from Cucumber features. Note that the documentation is generated from the source Cucumber feature files, and NOT from the test results (there are plenty of other tools that can do that).
cucumber-json-2-pdf This project aims to generate PDF reports based on cucumber json reports
Features2Cards Create PDFs from Cucumber Features and Scenarios for printing.
Frank Test iPhone/iPad applications using Cucumber
Gizmo A page model testing framework
Gherkin Editor for Windows Desktop app that has Excel-style editing for tables
Gherkin.mode for Coda2 Plugin for Coda2 that highlights syntax keywords of .feature file
Gherkin lint Uses Gherkin to parse feature files and runs linting against the default rules, and the optional rules you specified in your .gherkin-lintrc file.
Gherkingen Behaviour Driven Development (BDD) tests generator for Golang.
Ghokin Format and apply transformation on gherkin files
Gocure Gocure is a library that offers the possibility to generate beautiful html reports and it is also possible to embed any file in your Cucumber json reports. This can be done importing in a go project, executing a binary, calling a REST API or in a frontend using our docker container.
Groundwork Rails Template using Authlogic that comes with Cucumber Features
Guard::Cucumber Guard::Cucumber automatically runs your Features (much like autotest)
Gutkumber Integration testing for Ruby-GNOME2
Gwen A Gherkin interpreter for web automation (Selenium wrapper)
jEdit Cucumber Mode on github jEdit mode to add multi-lingual syntax highlighting for .feature files
Jeweler Craft the perfect RubyGem - with built-in Cucumber support
JSON_spec RSpec matchers and Cucumber Then Steps for validating JSON format data, especially useful for RESTful API Scenarios.
Melomel ActionScript, Flex and Air support for Cucumber
NetBeans IDE (B) Syntax highlighting
NewGem Use newgem -i cucumber to generate a bunch of helpful Scenario Steps for gem development
OCCukes Objective-C wire protocol implementation. Can be used for testing native iOS and Mac apps.
Online Gherkin Formatter and Validator Free online Gherkin editor, formatter and syntax validator. Website AssertThat
Pickle Model creation/reference in Cucumber - optionally leveraging your factories/blueprints
Pickler Synchronize user stories in Pivotal Tracker with Cucumber Features.
Pickles Docs Takes your specification (written in Gherkin, with Markdown descriptions) and turns them into an always up-to-date documentation of the current state of your software - in a variety of formats (HTML SPA, Static HTML, JSON, Word .docx, Excel)
Pitest-Cucumber-Plugin Cucumber integration for mutation testing tool PIT
Rcumber RCumber is a Rails plugin that gives your customers a web interface where they can view, edit and run Cucumber tests directly on your Rails project. No update since 2008
Relish Relish allows you to browse, search, and share your Cucumber Features on the web as living documentation. Supports public and private projects.
RSpec Use RSpec's Object.should and Object.should_not to compare values in your Step Definitions
rSquery Using jQuery matchers and more in Selenium. Aims to reduce the difficulties involved in writing Selenium tests in Cucumber environments for webapps that use jQuery.
JetBrains RubyMine Syntax highlighting and Test Runner UI
Schmorgurken Native Clojure Gherkin implementation (mostly compatible with Cucumber) that integrates with clojure-test
selenium-webdriver Developer-focused browser automation tool for IE, Firefox, Chrome
SpecFlow Online Gherkin Editor Simple Gherkin editor that enables you to quickly write, download and share feature files and scenarios โ€“ without any hassle, no content tracking
Swinger Write acceptance tests for Java/Swing Desktop apps using Cucumber!
Testjour Distributed test running (for Cucumber first).
theGardener A web application to retrieve features from a large number of projects, to organize them and generate proper documentation based on those BDD features.
Tidy Gherkin Google Chrome browser extension, that helps in step definition generation, Gherkin step and table formatting.
unobtainium-cucumber Integrate Cucumber with configuration driven Selenium or Appium drivers.
VCR Record and replay HTTP responses for fast, deterministic, accurate tests. Cucumber integration provided through the use of Tags.
Vim-Cucumber Feature syntax highlighting for Vim
Webrat Interact with a web application from Ruby. Works with Rails, and other web frameworks.
Webrat TM Bundle Collection of TextMate snippets for the webrat API.
Watir An open source Ruby library for automating tests. Watir interacts with a browser the same way people do: clicking links, filling out forms and validating text.
WatirCraft Web testing framework with Cucumber integration that builds on Watir.
watircuke Cucumber and H30 (watir, safariwatir, firewatir)
YARD-Cucumber Feature documentation integration with YARD

File: content/docs/tools/ruby.md


title: Ruby Tools weight: 1300

This page describes tools for a Ruby or Ruby on Rails environment.

IDEs

RubyMine

RubyMine is a Ruby and Rails IDE.

Build tools

Cucumber can be run in several ways.
Be aware that rake cucumber, cucumber features, and autotest with ENV AUTOFEATURE=true do not necessarily produce
the same results given the same features and step definitions.

Rake

Running rake cucumber from the command line provides the simplest method to run Cucumber tests.

Using Rake requires a Rakefile with a features task definition. For example:

ruby
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:features) do |t|
  t.cucumber_opts = "--format pretty" # Any valid command line option can go here.
end

This will run all the Features with the pretty formatter.

Note, how we use the cucumber_opts accessor to define our arguments passed to Cucumber.

If you are using Ruby on Rails, this task is defined for you already.

Now you can run Cucumber with Rake:

shell
rake features

The rake script provided with Cucumber performs much of the background magic required to get the test database and requisite
libraries properly loaded.
In fact, an important habit to acquire is to run Cucumber as a rake task immediately after performing a migration.
This ensures that the test database schema is kept in sync with the development database schema.
You can achieve the same effect by running rake db:test:prepare before your first Cucumber run following a migration
but developing the habit of running rake cucumber or rake cucumber:wip is probably the better course.

The Cucumber Rake task recognises the @wip Tag, so rake cucumber:wip will run only those scenarios tagged with @wip.

For example, given a feature file containing:

text
Feature: .  .  .

  Scenario: A

  @wip
  Scenario: B

  Scenario: C

Then running the command rake cucumber:wip will run the Steps contained inside Scenario B only,
while running rake cucumber:ok will run the Steps within all Scenarios other than B.

Using Profiles in Rake Tasks

For complex Feature runs that are tested often, it is nice to save the command line arguments as Cucumber profiles.

Once you have some profiles defined, you can use them in your Rake tasks, like so:

ruby
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

namespace :features do
  Cucumber::Rake::Task.new(:non_js) do |t|
    t.profile = "webrat"
  end

  Cucumber::Rake::Task.new(:selenium) do |t|
    t.profile = "selenium"
  end
end

Guarding Your production machines From Cucumber

Since Rake tasks are used on development and productions systems, it is generally a good idea to place a guard around your Cucumber task so your productions boxes don't need to install Cucumber.

Below is an example of how to do this. This example is the Rake task that Cucumber generates for Rails projects, but the same idea applies to any project using Cucumber and Rake:

ruby
require 'rubygems'

begin
  require 'cucumber'
  require 'cucumber/rake/task'

  Cucumber::Rake::Task.new(:features) do |t|
    t.cucumber_opts = "--format pretty"
  end

  task features: 'db:test:prepare'
rescue LoadError
  desc 'Cucumber rake task not available'
  task :features do
    abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
  end
end

Ruby on Rails

cucumber-rails

cucumber-rails is a RubyGem which
brings Ruby on Rails Generators for Cucumber with special support for Capybara
and DatabaseCleaner.

Installing

The cucumber:install generator sets up Cucumber in your Rails project. It
generates the necessary files in the features/ directory. After
running this generator you will also get a new rake task called cucumber.

For more details, see rails generate cucumber:install --help.

Usage

By default, cucumber-rails runs DatabaseCleaner.start and
DatabaseCleaner.clean before and after your Cucumber scenarios. This default
behavior can be disabled. See the
cucumber-rails README for details.

Resources

To learn more of the tools being integrated and assisted by cucumber-rails,
see the READMEs of
DatabaseCleaner and
Capybara.


File: content/docs/terms/_index.md


title: Terminology menu: main collapseChildren: true iconClass: far fa-book

There's loads of new terminology and jargon to learn as you learn about Cucumber and BDD. Here you'll find definitions of the common terms.