Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

The usage formatter also prints unused step definitions

  • Loading branch information...
commit 87ee1992155caa0f3ae51ba47923825150d9f55c 1 parent 7308cc6
Aslak Hellesøy authored April 01, 2009
1  History.txt
... ...
@@ -1,6 +1,7 @@
1 1
 == 0.2.4 (In Git)
2 2
 
3 3
 === New features
  4
+* The usage formatter also prints unused step definitions (Aslak Hellesøy)
4 5
 * Better exception if a World proc returns nil. (Aslak Hellesøy)
5 6
 * Allow Step Definitions to use |*varargs|, but only on Ruby 1.9. (Aslak Hellesøy)
6 7
 
6  examples/self_test/features/step_definitions/sample_steps.rb
@@ -62,3 +62,9 @@ def flunker
62 62
 Given /^failing expectation$/ do
63 63
   'this'.should == 'that'
64 64
 end
  65
+
  66
+Given /^unused$/ do
  67
+end
  68
+
  69
+Given /^another unused$/ do
  70
+end
3  features/usage.feature
@@ -103,6 +103,9 @@ Feature: Cucumber command line
103 103
        Given failing expectation # features/failing_expectation.feature:4
104 104
       /^failing$/    # features/step_definitions/sample_steps.rb:8
105 105
        Given failing # features/sample.feature:16
  106
+      (::) UNUSED (::)
  107
+      /^unused$/          # features/step_definitions/sample_steps.rb:66
  108
+      /^another unused$/  # features/step_definitions/sample_steps.rb:69
106 109
 
107 110
       """
108 111
 
16  lib/cucumber/formatter/usage.rb
@@ -10,6 +10,7 @@ def initialize(step_mother, io, options)
10 10
         @io = io
11 11
         @options = options
12 12
         @step_definitions = Hash.new { |h,step_definition| h[step_definition] = [] }
  13
+        @all_step_definitions = step_mother.step_definitions.dup
13 14
         @locations = []
14 15
       end
15 16
 
@@ -32,6 +33,7 @@ def visit_step_name(keyword, step_match, status, source_indent, background)
32 33
           description = format_step(keyword, step_match, status, nil)
33 34
           length = (keyword + step_match.format_args).jlength
34 35
           @step_definitions[step_match.step_definition] << [step_match, description, length, location]
  36
+          @all_step_definitions.delete(step_match.step_definition)
35 37
         end
36 38
       end
37 39
 
@@ -63,6 +65,20 @@ def print_summary
63 65
             @io.puts format_string(" # #{file_colon_line}".indent(max_length - length), :comment)
64 66
           end
65 67
         end
  68
+
  69
+        print_unused_step_definitions
  70
+      end
  71
+
  72
+      def print_unused_step_definitions
  73
+        if @all_step_definitions.any?
  74
+          max_length = @all_step_definitions.map{|step_definition| step_definition.text_length}.max
  75
+
  76
+          @io.puts format_string("(::) UNUSED (::)", :failed)
  77
+          @all_step_definitions.each do |step_definition|
  78
+            @io.print format_string(step_definition.regexp.inspect, :failed)
  79
+            @io.puts format_string("  # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment)
  80
+          end
  81
+        end
66 82
       end
67 83
     end
68 84
   end

0 notes on commit 87ee199

Please sign in to comment.
Something went wrong with that request. Please try again.