Read more

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

Ulrich Berkmueller
January 13, 2012Software engineer

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.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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.

Posted by Ulrich Berkmueller to makandra dev (2012-01-13 09:28)