Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of git://github.com/aslakhellesoy/cucumber

  • Loading branch information...
commit bb62216b6f9fe4ae0407ac0b59f6d53f781d7464 2 parents d220f7f + 87ee199
Joseph Wilk josephwilk authored
2  History.txt
... ... @@ -1,6 +1,8 @@
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)
  5 +* Better exception if a World proc returns nil. (Aslak Hellesøy)
4 6 * Allow Step Definitions to use |*varargs|, but only on Ruby 1.9. (Aslak Hellesøy)
5 7 * Snippets for steps that use Step Tables or Pystrings include block param and object type hint comment (#247 Joseph Wilk)
6 8 * Support description string for Backgrounds (#271 Joseph Wilk)
2  examples/i18n/sk/features/addition.feature
... ... @@ -1,5 +1,5 @@
1 1 Požiadavka: Sčítavanie
2   - Aby som sa vyhol hlúpim chybám
  2 + Aby som sa vyhol hlúpym chybám
3 3 Ako matematický idiot
4 4 Chcem vedieť ako sa sčítavajú dve čísla
5 5
2  examples/i18n/sk/features/division.feature
... ... @@ -1,5 +1,5 @@
1 1 Požiadavka: Delenie
2   - Aby som sa vyhol hlúpim chybám
  2 + Aby som sa vyhol hlúpym chybám
3 3 Pokladníci musia vedieť vypočítať podiel
4 4
5 5 Scenár: Prirodzené čísla
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
@@ -105,6 +105,9 @@ Feature: Cucumber command line
105 105 Given failing expectation # features/failing_expectation.feature:4
106 106 /^failing$/ # features/step_definitions/sample_steps.rb:8
107 107 Given failing # features/sample.feature:16
  108 + (::) UNUSED (::)
  109 + /^unused$/ # features/step_definitions/sample_steps.rb:66
  110 + /^another unused$/ # features/step_definitions/sample_steps.rb:69
108 111
109 112 """
110 113
6 lib/cucumber/formatter/html.rb
@@ -74,9 +74,11 @@ def visit_scenario_name(keyword, name, file_colon_line, source_indent)
74 74 end
75 75
76 76 def visit_outline_table(outline_table)
  77 + @outline_row = 0
77 78 @builder.table do
78 79 super(outline_table)
79 80 end
  81 + @outline_row = nil
80 82 end
81 83
82 84 def visit_examples_name(keyword, name)
@@ -145,10 +147,12 @@ def visit_table_row(table_row)
145 147 end
146 148 end
147 149 end
  150 + @outline_row += 1 if @outline_row
148 151 end
149 152
150 153 def visit_table_cell_value(value, width, status)
151   - @builder.td(value, :class => status, :id => "#{@row_id}_#{@col_index}")
  154 + cell_type = @outline_row == 0 ? :th : :td
  155 + @builder.__send__(cell_type, value, :class => status, :id => "#{@row_id}_#{@col_index}")
152 156 @col_index += 1
153 157 end
154 158
4 lib/cucumber/formatter/pretty.rb
@@ -157,10 +157,6 @@ def visit_py_string(string, status)
157 157 @io.flush
158 158 end
159 159
160   - def visit_table_cell(table_cell)
161   - super
162   - end
163   -
164 160 def visit_table_cell_value(value, width, status)
165 161 @io.print(' ' + format_string((value.to_s || '').ljust(width), status) + " #{@delim}")
166 162 @io.flush
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
15 lib/cucumber/step_mother.rb
@@ -45,6 +45,12 @@ def initialize(step_def_1, step_def_2)
45 45 end
46 46 end
47 47
  48 + class NilWorld < StandardError
  49 + def initialize
  50 + super("World procs should never return nil")
  51 + end
  52 + end
  53 +
48 54 # This is the main interface for registering step definitions, which is done
49 55 # from <tt>*_steps.rb</tt> files. This module is included right at the top-level
50 56 # so #register_step_definition (and more interestingly - its aliases) are
@@ -171,6 +177,15 @@ def new_world!
171 177 @current_world = Object.new
172 178 (@world_procs ||= []).each do |proc|
173 179 @current_world = proc.call(@current_world)
  180 + if @current_world.nil?
  181 + begin
  182 + raise NilWorld.new
  183 + rescue NilWorld => e
  184 + e.backtrace.clear
  185 + e.backtrace.push(proc.backtrace_line("World"))
  186 + raise e
  187 + end
  188 + end
174 189 end
175 190
176 191 @current_world.extend(World)
13 specs/cucumber/step_mother_spec.rb
@@ -85,5 +85,18 @@ module Cucumber
85 85 @step_mother.Given(/Three (.*) mice/) {|disability|}
86 86 end.should raise_error(Redundant)
87 87 end
  88 +
  89 + it "should raise an error if the world is nil" do
  90 + @step_mother.World do
  91 + end
  92 +
  93 + begin
  94 + @step_mother.before_and_after(nil)
  95 + raise "Should fail"
  96 + rescue => e
  97 + e.message.should == "World procs should never return nil"
  98 + e.backtrace.should == ["specs/cucumber/step_mother_spec.rb:90:in `World'"]
  99 + end
  100 + end
88 101 end
89 102 end

0 comments on commit bb62216

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