-
-
Save natritmeyer/904406 to your computer and use it in GitHub Desktop.
# Copyright (c) 2010, Nathaniel Ritmeyer. All rights reserved. | |
# | |
# http://www.natontesting.com | |
# | |
# Save this in a file called 'unused.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::Unused | |
# | |
# or... | |
# | |
# cucumber -d -f Unused | |
require 'cucumber/formatter/stepdefs' | |
class Unused < Cucumber::Formatter::Stepdefs | |
def print_summary(features) | |
add_unused_stepdefs | |
keys = @stepdef_to_match.keys.sort {|a,b| a.regexp_source <=> b.regexp_source} | |
puts "The following steps are unused...\n---------" | |
keys.each do |stepdef_key| | |
if @stepdef_to_match[stepdef_key].none? | |
puts "#{stepdef_key.regexp_source}\n#{stepdef_key.file_colon_line}\n---" | |
end | |
end | |
end | |
end |
What version of cucumber have you got? I wrote this against 0.10.2 (latest at time of writing)...
My bundle install:
...
Using cucumber (0.10.2)
...
I run:
bundle exec cucumber features/my_feature.feature -d -f Cucumber::Formatter::Unused
result:
no such file to load -- cucumber/formatter/unused
Error creating formatter: Cucumber::Formatter::Unused (LoadError)
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/constantize.rb:16:in require' /usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/constantize.rb:16:in
constantize'
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/configuration.rb:75:in formatter_class' /usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/configuration.rb:167:in
formatters'
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/configuration.rb:163:in map' /usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/configuration.rb:163:in
formatters'
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/configuration.rb:68:in build_tree_walker' /usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/runtime.rb:42:in
run!'
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/main.rb:43:in execute!' /usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/../lib/cucumber/cli/main.rb:20:in
execute'
/usr/lib/ruby/gems/1.8/gems/cucumber-0.10.2/bin/cucumber:14
/usr/bin/cucumber:19:in `load'
/usr/bin/cucumber:19
Unused.rb location:
ls -l features/support/unused.rb
-rw-r--r-- 1 leonardo leonardo 748 2011-04-06 19:58 features/support/unused.rb
thanks mate
Which one is it? The 2 errors you mention (comment #1 and #3) aren't the same...
This is the way worked:
cucumber -d -f Unused
not: cucumber -d -f Cucumber::Formatter::Unused
Yeah, that works too!
Just upgraded to Cucumber v2.4.0 and needed to tweak what is above:
require 'cucumber/formatter/stepdefs'
class Unused < Cucumber::Formatter::Stepdefs
def print_summary
add_unused_stepdefs
aggregate_info
@stepdef_to_match.keys
.sort_by { |stepdef| [stepdef.location.file, -stepdef.location.lines.first] }
.select { |stepdef| @stepdef_to_match[stepdef].none? }
.each do |stepdef|
$stdout.puts "#{stepdef.location.file}:#{stepdef.location.lines.first} # #{stepdef.regexp_source}"
end
end
end
uninitialized constant Cucumber::Formatter::Stepdefs (NameError)