Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

Step Definitions

aslakhellesoy edited this page Aug 13, 2010 · 40 revisions

A Step Definition is the Ruby counterpart of a plain text step. They consist of a Regexp and a Proc and are defined by calling one of the adjective / adverb methods. This happens before Cucumber starts to execute the plain text.

When Cucumber executes the plain text, it will for each step look for a registered Step Definition with a matching Regexp. The adjective/adverb has no significance when it comes to recognition. If it finds one it will execute its Proc, passing all groups from the Regexp match as arguments to the Proc.

Pending steps

When Cucumber can’t find a matching Step Definition the step gets marked as yellow, and all subsequent steps in the scenario are skipped.

Failed steps

When a Step Definition’s Proc is executed and raises an error, the step is marked as red.

Skipped steps

Steps that follow pending or failed steps are never executed (even if there is a matching Step Definition), and are marked cyan.

Ambiguous steps

Consider these step definitions:

Given /Three (.*) mice/ do |disability|
end

Given /Three blind (.*)/ do |animal|
end

And a plain text step:

Given Three blind mice

Cucumber can’t make a decision about what Step Definition to execute, and wil raise an error telling you to fix the ambiguity.

Duplicate Step Definitions

In Cucumber you’re not allowed to use a regexp more than once in a Step Definition (even across files, even with different code inside the Proc), so the following would cause an error:

Given /Three (.*) mice/ do |disability|
  # some code
end

Given /Three (.*) mice/ do |disability|
  # some other code
end

Clone this wiki locally