Skip to content

Instantly share code, notes, and snippets.

@jaredmoody
Forked from natritmeyer/unused.rb
Created November 29, 2012 01:25
Show Gist options
  • Save jaredmoody/4166112 to your computer and use it in GitHub Desktop.
Save jaredmoody/4166112 to your computer and use it in GitHub Desktop.
Cucumber formatter for printing unused steps alongside progress
# Copyright (c) 2010, Nathaniel Ritmeyer. All rights reserved.
#
# http://www.natontesting.com
#
# Save this in a file called 'unused_progress.rb' in your 'features/support' directory. Then, to list
# all the unused steps in your project, run the following command:
#
# cucumber -d -f Cucumber::Formatter::UnusedProgress
#
# or...
#
# cucumber -d -f UnusedProgress
require 'cucumber/formatter/stepdefs'
class UnusedProgress < Cucumber::Formatter::Stepdefs
def print_summary(features)
# print what progress normally prints
print_steps(:pending)
print_steps(:failed)
print_stats(features, @options)
print_snippets(@options)
print_passing_wip(@options)
# print unused steps only if we ran all features
if @options[:paths] == ["features"]
add_unused_stepdefs
keys = @stepdef_to_match.keys.sort {|a,b| a.regexp_source <=> b.regexp_source}
keys = keys.delete_if{|key| !@stepdef_to_match[key].none?}
unless keys.empty?
puts "The following steps are unused:\n"
keys.each do |stepdef_key|
puts "#{stepdef_key.regexp_source}\n#{stepdef_key.file_colon_line}\n"
end
puts
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment