Skip to content

Commit

Permalink
got basic dependencies working (altho dependencies run everytime they…
Browse files Browse the repository at this point in the history
…'re declared - updating to be able to run them only once)
  • Loading branch information
remi committed Mar 4, 2009
1 parent dac2d04 commit 0d44d0e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/testing_dependencies/load_more_stuff.rb
Expand Up @@ -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
6 changes: 6 additions & 0 deletions lib/scenarios/scenario.rb
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/scenario_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 0d44d0e

Please sign in to comment.