1 require File.dirname(__FILE__) + '/../story_helper'
6 describe StoryRunner do
7 it 'should collect all the stories' do
9 story_runner = StoryRunner.new(stub('scenario_runner'))
12 story_runner.Story 'title1', 'narrative1' do end
13 story_runner.Story 'title2', 'narrative2' do end
14 stories = story_runner.stories
17 story_runner.should have(2).stories
18 stories.first.title.should == 'title1'
19 stories.first.narrative.should == 'narrative1'
20 stories.last.title.should == 'title2'
21 stories.last.narrative.should == 'narrative2'
24 it 'should gather all the scenarios in the stories' do
26 story_runner = StoryRunner.new(stub('scenario_runner'))
29 story_runner.Story "story1", "narrative1" do
30 Scenario "scenario1" do end
31 Scenario "scenario2" do end
33 story_runner.Story "story2", "narrative2" do
34 Scenario "scenario3" do end
36 scenarios = story_runner.scenarios
39 story_runner.should have(3).scenarios
40 scenarios[0].name.should == 'scenario1'
41 scenarios[1].name.should == 'scenario2'
42 scenarios[2].name.should == 'scenario3'
45 # captures worlds passed into a ScenarioRunner
46 class ScenarioWorldCatcher
48 def run(scenario, world)
49 (@worlds ||= []) << world
53 it 'should run each scenario in a separate object' do
55 scenario_world_catcher = ScenarioWorldCatcher.new
56 story_runner = StoryRunner.new(scenario_world_catcher)
57 story_runner.Story 'story', 'narrative' do
58 Scenario 'scenario1' do end
59 Scenario 'scenario2' do end
63 story_runner.run_stories
66 worlds = scenario_world_catcher.worlds
67 scenario_world_catcher.should have(2).worlds
68 worlds[0].should_not == worlds[1]
71 it 'should use the provided world creator to create worlds' do
73 stub_scenario_runner = stub_everything
74 mock_world_creator = mock('world creator')
75 story_runner = StoryRunner.new(stub_scenario_runner, mock_world_creator)
76 story_runner.Story 'story', 'narrative' do
77 Scenario 'scenario1' do end
78 Scenario 'scenario2' do end
82 mock_world_creator.should_receive(:create).twice
85 story_runner.run_stories
90 it 'should notify listeners of the scenario count when the run starts' do
92 story_runner = StoryRunner.new(stub_everything)
93 mock_listener1 = stub_everything('listener1')
94 mock_listener2 = stub_everything('listener2')
95 story_runner.add_listener(mock_listener1)
96 story_runner.add_listener(mock_listener2)
98 story_runner.Story 'story1', 'narrative1' do
99 Scenario 'scenario1' do end
101 story_runner.Story 'story2', 'narrative2' do
102 Scenario 'scenario2' do end
103 Scenario 'scenario3' do end
107 mock_listener1.should_receive(:run_started).with(3)
108 mock_listener2.should_receive(:run_started).with(3)
111 story_runner.run_stories
116 it 'should notify listeners when a story starts' do
118 story_runner = StoryRunner.new(stub_everything)
119 mock_listener1 = stub_everything('listener1')
120 mock_listener2 = stub_everything('listener2')
121 story_runner.add_listener(mock_listener1)
122 story_runner.add_listener(mock_listener2)
124 story_runner.Story 'story1', 'narrative1' do
125 Scenario 'scenario1' do end
127 story_runner.Story 'story2', 'narrative2' do
128 Scenario 'scenario2' do end
129 Scenario 'scenario3' do end
133 mock_listener1.should_receive(:story_started).with('story1', 'narrative1')
134 mock_listener1.should_receive(:story_ended).with('story1', 'narrative1')
135 mock_listener2.should_receive(:story_started).with('story2', 'narrative2')
136 mock_listener2.should_receive(:story_ended).with('story2', 'narrative2')
139 story_runner.run_stories
144 it 'should notify listeners when the run ends' do
146 story_runner = StoryRunner.new(stub_everything)
147 mock_listener1 = stub_everything('listener1')
148 mock_listener2 = stub_everything('listener2')
149 story_runner.add_listener mock_listener1
150 story_runner.add_listener mock_listener2
151 story_runner.Story 'story1', 'narrative1' do
152 Scenario 'scenario1' do end
156 mock_listener1.should_receive(:run_ended)
157 mock_listener2.should_receive(:run_ended)
160 story_runner.run_stories
165 it 'should run a story in an instance of a specified class' do
167 scenario_world_catcher = ScenarioWorldCatcher.new
168 story_runner = StoryRunner.new(scenario_world_catcher)
169 story_runner.Story 'title', 'narrative', :type => String do
170 Scenario 'scenario' do end
174 story_runner.run_stories
177 scenario_world_catcher.worlds[0].should be_kind_of(String)
178 scenario_world_catcher.worlds[0].should be_kind_of(World)
181 it 'should pass initialization params through to the constructed instance' do
183 scenario_world_catcher = ScenarioWorldCatcher.new
184 story_runner = StoryRunner.new(scenario_world_catcher)
185 story_runner.Story 'title', 'narrative', :type => Array, :args => [3] do
186 Scenario 'scenario' do end
190 story_runner.run_stories
193 scenario_world_catcher.worlds[0].should be_kind_of(Array)
194 scenario_world_catcher.worlds[0].size.should == 3
197 it 'should find a scenario in the current story by name' do
199 story_runner = StoryRunner.new(ScenarioRunner.new)
202 story_runner.Story 'title', 'narrative' do
203 Scenario 'first scenario' do
205 Scenario 'second scenario' do
206 $scenario = StoryRunner.scenario_from_current_story 'first scenario'
211 story_runner.run_stories
214 $scenario.name.should == 'first scenario'
217 it "should clean the steps between stories" do
219 story_runner = StoryRunner.new(ScenarioRunner.new)
220 result = mock 'result'
222 step1 = Step.new('step') do
225 steps1 = StepGroup.new
226 steps1.add :when, step1
228 story_runner.Story 'title', 'narrative', :steps => steps1 do
229 Scenario 'first scenario' do
234 step2 = Step.new('step') do
237 steps2 = StepGroup.new
238 steps2.add :when, step2
240 story_runner.Story 'title2', 'narrative', :steps => steps2 do
241 Scenario 'second scenario' do
247 result.should_receive(:one)
248 result.should_receive(:two)
251 story_runner.run_stories