February 2013
Intermediate to advanced
272 pages
5h 45m
English
| Recipe 5 | Define Steps as Regular Ruby Methods |
You’d like your step definitions to be plain Ruby methods so that they’re easier to edit, test, and maintain.
Cucumber’s built-in support for invoking Ruby methods directly[34]
(Optional) Mechanize[35] to run the examples with live data
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 ...