Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit bb62216b6f9fe4ae0407ac0b59f6d53f781d7464 2 parents d220f7f + 87ee199
@josephwilk josephwilk authored
View
2  History.txt
@@ -1,6 +1,8 @@
== 0.2.4 (In Git)
=== New features
+* The usage formatter also prints unused step definitions (Aslak Hellesøy)
+* Better exception if a World proc returns nil. (Aslak Hellesøy)
* Allow Step Definitions to use |*varargs|, but only on Ruby 1.9. (Aslak Hellesøy)
* Snippets for steps that use Step Tables or Pystrings include block param and object type hint comment (#247 Joseph Wilk)
* Support description string for Backgrounds (#271 Joseph Wilk)
View
2  examples/i18n/sk/features/addition.feature
@@ -1,5 +1,5 @@
Požiadavka: Sčítavanie
- Aby som sa vyhol hlúpim chybám
+ Aby som sa vyhol hlúpym chybám
Ako matematický idiot
Chcem vedieť ako sa sčítavajú dve čísla
View
2  examples/i18n/sk/features/division.feature
@@ -1,5 +1,5 @@
Požiadavka: Delenie
- Aby som sa vyhol hlúpim chybám
+ Aby som sa vyhol hlúpym chybám
Pokladníci musia vedieť vypočítať podiel
Scenár: Prirodzené čísla
View
6 examples/self_test/features/step_definitions/sample_steps.rb
@@ -62,3 +62,9 @@ def flunker
Given /^failing expectation$/ do
'this'.should == 'that'
end
+
+Given /^unused$/ do
+end
+
+Given /^another unused$/ do
+end
View
3  features/usage.feature
@@ -105,6 +105,9 @@ Feature: Cucumber command line
Given failing expectation # features/failing_expectation.feature:4
/^failing$/ # features/step_definitions/sample_steps.rb:8
Given failing # features/sample.feature:16
+ (::) UNUSED (::)
+ /^unused$/ # features/step_definitions/sample_steps.rb:66
+ /^another unused$/ # features/step_definitions/sample_steps.rb:69
"""
View
6 lib/cucumber/formatter/html.rb
@@ -74,9 +74,11 @@ def visit_scenario_name(keyword, name, file_colon_line, source_indent)
end
def visit_outline_table(outline_table)
+ @outline_row = 0
@builder.table do
super(outline_table)
end
+ @outline_row = nil
end
def visit_examples_name(keyword, name)
@@ -145,10 +147,12 @@ def visit_table_row(table_row)
end
end
end
+ @outline_row += 1 if @outline_row
end
def visit_table_cell_value(value, width, status)
- @builder.td(value, :class => status, :id => "#{@row_id}_#{@col_index}")
+ cell_type = @outline_row == 0 ? :th : :td
+ @builder.__send__(cell_type, value, :class => status, :id => "#{@row_id}_#{@col_index}")
@col_index += 1
end
View
4 lib/cucumber/formatter/pretty.rb
@@ -157,10 +157,6 @@ def visit_py_string(string, status)
@io.flush
end
- def visit_table_cell(table_cell)
- super
- end
-
def visit_table_cell_value(value, width, status)
@io.print(' ' + format_string((value.to_s || '').ljust(width), status) + " #{@delim}")
@io.flush
View
16 lib/cucumber/formatter/usage.rb
@@ -10,6 +10,7 @@ def initialize(step_mother, io, options)
@io = io
@options = options
@step_definitions = Hash.new { |h,step_definition| h[step_definition] = [] }
+ @all_step_definitions = step_mother.step_definitions.dup
@locations = []
end
@@ -32,6 +33,7 @@ def visit_step_name(keyword, step_match, status, source_indent, background)
description = format_step(keyword, step_match, status, nil)
length = (keyword + step_match.format_args).jlength
@step_definitions[step_match.step_definition] << [step_match, description, length, location]
+ @all_step_definitions.delete(step_match.step_definition)
end
end
@@ -63,6 +65,20 @@ def print_summary
@io.puts format_string(" # #{file_colon_line}".indent(max_length - length), :comment)
end
end
+
+ print_unused_step_definitions
+ end
+
+ def print_unused_step_definitions
+ if @all_step_definitions.any?
+ max_length = @all_step_definitions.map{|step_definition| step_definition.text_length}.max
+
+ @io.puts format_string("(::) UNUSED (::)", :failed)
+ @all_step_definitions.each do |step_definition|
+ @io.print format_string(step_definition.regexp.inspect, :failed)
+ @io.puts format_string(" # #{step_definition.file_colon_line}".indent(max_length - step_definition.text_length), :comment)
+ end
+ end
end
end
end
View
15 lib/cucumber/step_mother.rb
@@ -45,6 +45,12 @@ def initialize(step_def_1, step_def_2)
end
end
+ class NilWorld < StandardError
+ def initialize
+ super("World procs should never return nil")
+ end
+ end
+
# This is the main interface for registering step definitions, which is done
# from <tt>*_steps.rb</tt> files. This module is included right at the top-level
# so #register_step_definition (and more interestingly - its aliases) are
@@ -171,6 +177,15 @@ def new_world!
@current_world = Object.new
(@world_procs ||= []).each do |proc|
@current_world = proc.call(@current_world)
+ if @current_world.nil?
+ begin
+ raise NilWorld.new
+ rescue NilWorld => e
+ e.backtrace.clear
+ e.backtrace.push(proc.backtrace_line("World"))
+ raise e
+ end
+ end
end
@current_world.extend(World)
View
13 specs/cucumber/step_mother_spec.rb
@@ -85,5 +85,18 @@ module Cucumber
@step_mother.Given(/Three (.*) mice/) {|disability|}
end.should raise_error(Redundant)
end
+
+ it "should raise an error if the world is nil" do
+ @step_mother.World do
+ end
+
+ begin
+ @step_mother.before_and_after(nil)
+ raise "Should fail"
+ rescue => e
+ e.message.should == "World procs should never return nil"
+ e.backtrace.should == ["specs/cucumber/step_mother_spec.rb:90:in `World'"]
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.