3
votes

I have just started using cucumber and am seeking clarification whether the folder having my step definitions must be named exactly as step_defnitions or can it be anything (e.g. my_defs). I tried renaming in my local machine but sometimes it works and sometimes doesn't.

features/
|
|-- step_definitions/ 
2
would love to help but am not sure what the question is. Are you trying to see if there is a folder inside your current directory? or possibly just checking for a file? - Dan Bradbury

2 Answers

4
votes

Cucumber will automatically load any files within the features folder. This means that your step definition files can be located in any folder name/structure as long as they are in the features folder.

Note that it is possible to override this setting and explicitly state the location of your steps by doing:

cucumber -r your/steps/folder/location

For more details you can see the help - cucumber -h:

-r: Require files before executing the features. If this option is not specified, all *.rb files that are siblings or below the features will be loaded auto-matically. Automatic loading is disabled when this option is specified, and all loading becomes explicit. Files under directories named "support" are always loaded first. This option can be specified multiple times.

1
votes

In every reference I've seen (including the RSpec Book), they always have a "step_definitions" folder for definitions. A lot of things in Ruby (and especially Rails) utilize a "convention over configuration" philosophy, and I believe this is one of those things. I think it'd be less hassle for you to just make the "step_definitions" folder inside the "features" folder and know that it should work than to try and figure out how to change the configuration.