How to organize and execute cucumber features (e.g. in subdirectories)

Updated . Posted . Visible to the public.

In cucumber you are able to run features in whatever directory you like. This also includes executing features in subdirectories. There are only some things you have to take care of.

By default, cucumber loads all *.rb files it can find (recursively) within the directory you passed as argument to cucumber.

$ cucumber # defaults to directory "features"
$ cucumber features
$ cucumber my/custom/features/dir

So, if you would like to organize features in subdirectories, you won't have any problems when running the whole test-suite. Cucumber will automatically load and run features in subdirectories, too.

However, running features in subdirectories does not work out of the box. The reason for this is that cucumber will look for your step definitions and support files within the subdirectory.

What you can do now is to either provide all needed support files and step definitions also within the subdirectories (not practicable) OR use the -r command line argument when running the subdirectory features:

$ cucumber --help

[...]
-r, --require LIBRARY|DIR        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.
[...]
        
$ cucumber -r features

This tells cucumber to load your support and step definition files from the features' root directory.

Fazit

If you re-organize the features of a project into a subfolders, always put the -r features option to your config/cucumber.yml file at the end of your profiles (maybe at the end of stdopts). This way developers working on the project don't have to provide the option for every cucumber test run execution.

Ulrich Berkmüller
Last edit
Judith Roth
License
Source code in this card is licensed under the MIT License.
Posted by Ulrich Berkmüller to makandra dev (2012-01-13 08:28)