Permalink
Browse files

Better exception if a World proc returns nil.

  • Loading branch information...
1 parent e58e1ed commit 6c7f039ac2874775558734108f40ed1c61e1466b @aslakhellesoy aslakhellesoy committed Mar 31, 2009
Showing with 29 additions and 0 deletions.
  1. +1 −0 History.txt
  2. +15 −0 lib/cucumber/step_mother.rb
  3. +13 −0 specs/cucumber/step_mother_spec.rb
View
@@ -1,6 +1,7 @@
== 0.2.4 (In Git)
=== New features
+* 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)
== 0.2.3 2009-03-30
@@ -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)
@@ -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

0 comments on commit 6c7f039

Please sign in to comment.