Cucumber formatter for unused steps

As time goes on in a project using cucumber you’ll end up with some steps which no longer get called, and you probably want to delete them. Annoyingly, there isn’t a built-in formatter you can use to find out where they are. Sure, the ‘usage’ formatter prints off unused steps, but it prints off all the other steps too! What’s needed is a formatter that will hunt down all steps that are not being used and then print off each step’s name and its location (file location and line number).

What follows is a very basic cucumber formatter that will do just that. To use it, copy the code into a file called ‘unused.rb‘ in your ‘features/support‘ folder and then use the formatter when you run cucumber:

cucumber -d -f Cucumber::Formatter::Unused

or

cucumber -d -f Unused

7 thoughts on “Cucumber formatter for unused steps

  1. Sadly this seems to list **every** step in my specs. I’m using the most recent Rails and Cucumber versions.

  2. I changed your formatter to ignore any steps inside a debug_steps.rb file like this:

    puts “#{stepdef_key.regexp_source}\n#{stepdef_key.file_colon_line}\n—” unless stepdef_key.file_colon_line.match /\/debug_steps.rb:\d+$/

  3. This is actually built into Cucumber. Run the following:

    bundle exec cucumber –format usage

    It will print out unused steps at the bottom. (and most-used steps at the top, also handy)

  4. Pingback: Using guard to check for unused Cucumber steps | ELEVATION Dev Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>