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

Calling Steps from Step Definitions

aslakhellesoy edited this page Aug 13, 2010 · 23 revisions

It is possible to call steps from step definitions:

Given /^The user (.*) exists$/ do |name|
  # ...
end

Given /^I log in as (.*)$/ do |name|
  # ...
end

Given /^(.*) is logged in$/ do |name|
  Given "The user #{name} exists"
  Given "I log in as #{name}"
end

This is pracical if you have several common steps that you want to perform in several scenarios. This allows you to do this in a Scenario:

Scenario: View last incidents
  Given Linda is logged in # This will in fact invoke 2 step definitions
  When I go to the incident page

Instead of having a lot of repetition:

Scenario: View last incidents
  Given The user Linda exists
  And I log in as Linda
  When I go to the incident page

Clone this wiki locally