Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ScenarioRunner runs steps in the world

  • Loading branch information...
commit dd777c2809acd8975e5a0169cf13b41f66bf83e1 1 parent 825018a
Les Hill leshill authored
1  lib/turnip.rb
View
@@ -16,6 +16,7 @@ module Turnip
autoload :Table, 'turnip/table'
autoload :StepLoader, 'turnip/step_loader'
autoload :StepModule, 'turnip/step_module'
+ autoload :ScenarioRunner, 'turnip/scenario_runner'
autoload :ScenarioContext, 'turnip/scenario_context'
class << self
33 lib/turnip/scenario_runner.rb
View
@@ -0,0 +1,33 @@
+module Turnip
+ class ScenarioRunner
+ attr_accessor :available_steps
+ attr_accessor :context
+ attr_accessor :world
+
+ def initialize(world)
+ self.world = world
+ end
+
+ def load(context)
+ self.context = context
+ context.modules.each {|mod| world.extend mod }
+ self
+ end
+
+ def run
+ self.available_steps = context.available_background_steps
+ context.backgrounds.each do |background|
+ run_steps(background.steps)
+ end
+
+ self.available_steps = context.available_scenario_steps
+ run_steps(context.scenario.steps)
+ end
+
+ def run_steps(steps)
+ steps.each do |step|
+ Turnip::StepDefinition.execute(world, available_steps, step)
+ end
+ end
+ end
+end
71 spec/scenario_runner_spec.rb
View
@@ -0,0 +1,71 @@
+require 'spec_helper'
+
+describe Turnip::ScenarioRunner do
+ let(:runner) { Turnip::ScenarioRunner.new(world) }
+ let(:world) { Object.new }
+
+ describe '#initialize' do
+ it 'keeps track of the world' do
+ Turnip::ScenarioRunner.new(world).world.should eq(world)
+ end
+ end
+
+ describe '#load' do
+ let(:context) { stub(:modules => [some_module]) }
+ let(:some_module) { Module.new }
+
+ it 'is chainable' do
+ runner.load(context).should eq(runner)
+ end
+
+ it 'keeps track of the scenario context' do
+ runner.load(context).context.should eq(context)
+ end
+
+ it 'loads the given modules into the world' do
+ runner.load(context).world.should be_kind_of(some_module)
+ end
+ end
+
+ describe '#run' do
+ it 'iterates over the background steps' do
+ runner.context = stub(:backgrounds => (0..2).map { stub(:steps => [stub]) },
+ :available_background_steps => [],
+ :available_scenario_steps => [],
+ :scenario => stub(:steps => []))
+
+ Turnip::StepDefinition.should_receive(:execute).exactly(3).times
+ runner.run
+ end
+
+ it 'iterates over the scenario steps' do
+ runner.context = stub(:backgrounds => [],
+ :available_background_steps => [],
+ :available_scenario_steps => [],
+ :scenario => stub(:steps => (0..3)))
+
+ Turnip::StepDefinition.should_receive(:execute).exactly(4).times
+ runner.run
+ end
+ end
+
+ describe '#run_steps' do
+ let(:available_steps) { stub }
+
+ it 'executes the steps with the current world' do
+ step = stub
+ steps = [step]
+ runner.available_steps = available_steps
+
+ Turnip::StepDefinition.should_receive(:execute).with(world, available_steps, step)
+ runner.run_steps(steps)
+ end
+
+ it 'iterates over the steps' do
+ steps = (0..2)
+
+ Turnip::StepDefinition.should_receive(:execute).exactly(3).times
+ runner.run_steps(steps)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.