Read more

Cucumber: How to find unused step definitions

Dominik Schöler
November 28, 2018Software engineer at makandra GmbH

Cucumber has an output format that prints step definitions only. You can use this to find unused ones:

  1. Temporarily add require_relative 'env' to the top of the first file in features/support. --dry-run makes Cucumber skip loading env.rb.
  2. Open a really wide terminal window.
  3. bundle exec cucumber --dry-run --format stepdefs | grep -B1 'NOT MATCHED' --no-group-separator | grep features/step_definitions
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

This will print all unused step definitions from your project – however, the result will include false positives. Steps that are exclusively called from other steps will be in the list. Assure a step is not used before removing it.

If you remove the --dry-run flag, all tests will actually run and you can skip adding the require_relative line. It will take much longer, but provide more accurate results.

Posted by Dominik Schöler to makandra dev (2018-11-28 14:55)