Permalink
Browse files

Yield existing world object to World block [#87 state:resolved milest…

…one_id:0.1.10]
  • Loading branch information...
aslakhellesoy committed Nov 23, 2008
1 parent aea226c commit fc584ebf871cc002c7f83c7eabcab6215c89732a
View
@@ -10,6 +10,7 @@ You can now run multiple features at specific lines numbers like this:
This will run foo.feature at line 15 and bar.feature at line 6, 45 and 111.
=== New features
+* Yield existing world object to World block (#87 Aslak Hellesøy)
* AUTOFEATURE=tRue works (case insensitive) (Aslak Hellesøy)
* Support for .NET via IronRuby. See examples for details. (Aslak Hellesøy)
* Lithuanian translation (sauliusgrigaitis)
@@ -0,0 +1,6 @@
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+require 'cucumber/rake/task'
+
+Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = "--format pretty"
+end
@@ -0,0 +1,15 @@
+require 'test/unit/assertions'
+World do |o|
+ o.extend(Test::Unit::Assertions)
+ o
+end
+
+Given /^(\w+) = (\w+)$/ do |var, value|
+ instance_variable_set("@#{var}", value)
+end
+
+Then /^I can assert that (\w+) == (\w+)$/ do |var_a, var_b|
+ a = instance_variable_get("@#{var_a}")
+ b = instance_variable_get("@#{var_b}")
+ assert_equal(a, b)
+end
@@ -0,0 +1,9 @@
+Feature: Test::Unit
+ In order to please people who like Test::Unit
+ As a Cucumber user
+ I want to be able to use assert* in my step definitions
+
+ Scenario: assert_equal
+ Given x = 5
+ And y = 5
+ Then I can assert that x == y
View
@@ -7,9 +7,7 @@ class Executor
attr_writer :scenario_names, :lines_for_features
def initialize(step_mother)
- @world_proc = lambda do
- Object.new
- end
+ @world_procs = []
@before_scenario_procs = []
@after_scenario_procs = []
@after_step_procs = []
@@ -20,7 +18,7 @@ def initialize(step_mother)
end
def register_world_proc(&proc)
- @world_proc = proc
+ @world_procs << proc
end
def register_before_scenario_proc(&proc)
@@ -80,7 +78,7 @@ def execute_scenario(scenario)
@error = nil
@pending = nil
- @world = @world_proc.call
+ @world = create_world
@world.extend(Spec::Matchers) if defined?(Spec::Matchers)
define_step_call_methods(@world)
@@ -181,5 +179,12 @@ def lines_defined_for_current_feature?
@lines_for_features && !@lines_for_features[@feature_file].nil? && !@lines_for_features[@feature_file].empty?
end
+ def create_world
+ world = Object.new
+ @world_procs.each do |world_proc|
+ world = world_proc.call(world)
+ end
+ world
+ end
end
end
@@ -51,6 +51,32 @@ def mock_scenario(stubs = {})
})
end
+ describe "creating a world" do
+ module DoitExtension
+ def doit
+ "dunit"
+ end
+ end
+
+ module BeatitExtension
+ def beatit
+ "beatenit"
+ end
+ end
+
+ it "should yield an Object to the world proc" do
+ @executor.register_world_proc do |world|
+ world.extend(DoitExtension)
+ end
+ @executor.register_world_proc do |world|
+ world.extend(BeatitExtension)
+ end
+ world = @executor.create_world
+ world.doit.should == "dunit"
+ world.beatit.should == "beatenit"
+ end
+ end
+
describe "visiting feature" do
it "should set the feature file being visited" do

0 comments on commit fc584eb

Please sign in to comment.