Read more

Cucumber: Calling multiple steps from a step definition

Henning Koch
July 11, 2012Software engineer at makandra GmbH

When refactoring a sequence of steps to a new, more descriptive step, you can use the steps method and Ruby's %-notation Show archive.org snapshot like this:

Given 'I have an article in my cart' do
  steps %(
    When I go the article list
    And I open the first article
    And I press "Add to cart"
  )
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

This way you can simply copy the steps over without any changes.

Warning: Apparently, steps processes its argument with the Gherkin parser, meaning only lines starting with the Gherkin keywords Given/When/Then/And/But will be considered. In other words, lines not starting with these keywords will be silently ignored!

There is a very similar method step that takes a single step without Gherkin keyword. It is used like this:

Given 'I have an article in my cart' do
  step 'I go the article list'
  step 'I open the first article'
  step 'I press "Add to cart"'
end

Remember the difference.

Posted by Henning Koch to makandra dev (2012-07-11 15:42)