Specifying the Location of Step Definitions

Have you ever wondered how Cucumber finds your step definitions? There is nothing in Cucumber that expects them to be under features/step_definitions. In fact, if you renamed these two directories to jolly/jumper and ran cucumber jolly, things would work just as well.

Cucumber recursively scans some directories for .rb files to load, and if there are step definitions in them (or hooks or transforms), they get loaded. It’s important to understand what directories Cucumber scans. Once you understand this, you will save yourself from a common source of confusion and frustration. Let’s illustrate that with an example. Assume you have organized your features and step definitions as follows:

 
features ...

Get The Cucumber Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.