Created
April 5, 2011 20:00
-
-
Save natritmeyer/904406 to your computer and use it in GitHub Desktop.
Cucumber formatter for printing unused steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which one is it? The 2 errors you mention (comment #1 and #3) aren't the same...