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
I find this very useful on projects I am on, thanks!
Sadly this seems to list **every** step in my specs. I’m using the most recent Rails and Cucumber versions.
Oh I’m very sorry, it was my error. Useful formatter, thanks!
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+$/
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)
Oops, only just now read the top of your post. Well, for me the usage formatter works just fine, I don’t mind the output.
Pingback: Using guard to check for unused Cucumber steps | ELEVATION Dev Blog