From 0d44d0e26fd855f14261d332b19b8e5ee73e343c Mon Sep 17 00:00:00 2001 From: remi Date: Wed, 4 Mar 2009 01:09:42 -0700 Subject: [PATCH] got basic dependencies working (altho dependencies run everytime they're declared - updating to be able to run them only once) --- .../testing_dependencies/load_more_stuff.rb | 3 ++ lib/scenarios/scenario.rb | 6 ++++ spec/scenario_spec.rb | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/examples/testing_dependencies/load_more_stuff.rb b/examples/testing_dependencies/load_more_stuff.rb index 74f0178..b348e2f 100644 --- a/examples/testing_dependencies/load_more_stuff.rb +++ b/examples/testing_dependencies/load_more_stuff.rb @@ -3,5 +3,8 @@ # does this # and that # +# --- +# dependencies: [ :load_stuff ] +# $times_loads_more_stuff_has_been_run ||= 0 $times_loads_more_stuff_has_been_run += 1 diff --git a/lib/scenarios/scenario.rb b/lib/scenarios/scenario.rb index b32cd71..52b1d16 100644 --- a/lib/scenarios/scenario.rb +++ b/lib/scenarios/scenario.rb @@ -147,7 +147,13 @@ def load *scenarios begin if scenario.is_a?Scenario puts "loading scenario: #{ scenario.file_path }" if Scenario.verbose + + # TODO update to eval ... should load in a custom context ... + # the eval should also catch exceptions and print the + # line number that threw the exception, etc etc Kernel::load scenario.file_path + + self.load *scenario.dependencies if scenario.dependencies else puts "Unsure how to load scenario: #{ scenario.inspect }" end diff --git a/spec/scenario_spec.rb b/spec/scenario_spec.rb index 9631459..43ffb54 100644 --- a/spec/scenario_spec.rb +++ b/spec/scenario_spec.rb @@ -91,6 +91,34 @@ def path_to_more_scenarios $set_by_first_scenario.should == 'hello from first scenario!' end + it 'should be able to load multiple scenarios and run any dependencies' do + path = File.join File.dirname(__FILE__), '..', 'examples', 'testing_dependencies' + Scenario.load_paths << path + + Scenario[:load_more_stuff].dependencies.should include(:load_stuff) + + $times_loads_stuff_has_been_run.should be_nil + $times_loads_more_stuff_has_been_run.should be_nil + + Scenario.load :load_stuff + $times_loads_stuff_has_been_run.should == 1 + $times_loads_more_stuff_has_been_run.should be_nil + + Scenario.load :load_stuff, :load_stuff + $times_loads_stuff_has_been_run.should == 3 + $times_loads_more_stuff_has_been_run.should be_nil + + Scenario.load :load_more_stuff + $times_loads_stuff_has_been_run.should == 4 # should be run once, as it's a dependency + $times_loads_more_stuff_has_been_run.should == 1 + + Scenario.load :load_stuff, :load_more_stuff + $times_loads_stuff_has_been_run.should == 6 # should be run twice + $times_loads_more_stuff_has_been_run.should == 2 + end + + it 'should be able to load multiple scenarios and run any dependencies (running each dependency only once!)' + it 'should be able to load multiple scenarios' do Scenario.load_paths << path_to_more_scenarios