Skip to Main Content
Cucumber Recipes
book

Cucumber Recipes

by Ian Dees, Matt Wynne, Aslak Hellesoy
February 2013
Intermediate to advanced content levelIntermediate to advanced
272 pages
5h 45m
English
Pragmatic Bookshelf
Content preview from Cucumber Recipes
Recipe 5Define Steps as Regular Ruby Methods

Problem

You’d like your step definitions to be plain Ruby methods so that they’re easier to edit, test, and maintain.

Ingredients

  • Cucumber’s built-in support for invoking Ruby methods directly[34]

  • (Optional) Mechanize[35] to run the examples with live data

Solution

Cucumber step definitions are pretty easy to put together. You just tie together a regular expression with a block of code. Ideally, these blocks of code should be really short—perhaps a method invocation or two and some data massaging.

Over time, it can be tempting to let more and more code creep into your step definitions. They can become harder to read and maintain.

Regular Ruby methods don’t have this problem. They’re easy to refactor ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Cucumber Cookbook

Cucumber Cookbook

Shankar Garg
Basiswissen Softwaretest , 6th Edition

Basiswissen Softwaretest , 6th Edition

Andreas Spillner, Tilo Linz
React Cookbook

React Cookbook

David Griffiths, Dawn Griffiths

Publisher Resources

ISBN: 9781941222607Errata