Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / spec / spec / story / runner / scenario_runner_spec.rb
blobe37cb5bd6f58c387fb67e71fede9e95ba7a78bbc
1 require File.dirname(__FILE__) + '/../story_helper'
3 module Spec
4   module Story
5     module Runner
6       describe ScenarioRunner do
7         it 'should run a scenario in its story' do
8           # given
9           world = stub_everything
10           scenario_runner = ScenarioRunner.new
11           $answer = nil
12           story = Story.new 'story', 'narrative' do
13             @answer = 42 # this should be available to the scenario
14           end
15           scenario = Scenario.new story, 'scenario' do
16             $answer = @answer
17           end
18           
19           # when
20           scenario_runner.run(scenario, world)
21           
22           # then
23           ensure_that $answer, is(42)
24         end
25         
26         it 'should allow scenarios to share methods' do
27           # given
28           world = stub_everything
29           $shared_invoked = 0
30           story = Story.new 'story', 'narrative' do
31             def shared
32               $shared_invoked += 1
33             end
34           end
35           scenario1 = Scenario.new story, 'scenario1' do
36             shared()
37           end
38           scenario2 = Scenario.new story, 'scenario2' do
39             shared()
40           end
41           scenario_runner = ScenarioRunner.new
42           
43           # when
44           scenario_runner.run(scenario1, world)
45           scenario_runner.run(scenario2, world)
46           
47           # then
48           $shared_invoked.should == 2
49         end
50         
51         it 'should notify listeners when a scenario starts' do
52           # given
53           world = stub_everything
54           story = Story.new 'story', 'narrative' do end
55           scenario = Scenario.new story, 'scenario1' do
56             # succeeds
57           end
58           scenario_runner = ScenarioRunner.new
59           mock_listener1 = stub_everything('listener1')
60           mock_listener2 = stub_everything('listener2')
61           scenario_runner.add_listener(mock_listener1)
62           scenario_runner.add_listener(mock_listener2)
63           
64           # expect
65           mock_listener1.should_receive(:scenario_started).with('story', 'scenario1')
66           mock_listener2.should_receive(:scenario_started).with('story', 'scenario1')
67           
68           # when
69           scenario_runner.run(scenario, world)
70           
71           # then
72           # TODO verify_all
73         end
74         
75         it 'should notify listeners when a scenario succeeds' do
76           # given
77           world = stub_everything('world')
78           story = Story.new 'story', 'narrative' do end
79           scenario = Scenario.new story, 'scenario1' do
80             # succeeds
81           end
82           scenario_runner = ScenarioRunner.new
83           mock_listener1 = stub_everything('listener1')
84           mock_listener2 = stub_everything('listener2')
85           scenario_runner.add_listener(mock_listener1)
86           scenario_runner.add_listener(mock_listener2)
87           
88           # expect
89           mock_listener1.should_receive(:scenario_succeeded).with('story', 'scenario1')
90           mock_listener2.should_receive(:scenario_succeeded).with('story', 'scenario1')
91           
92           # when
93           scenario_runner.run(scenario, world)
94           
95           # then
96           # TODO verify_all
97         end
98         
99         it 'should notify listeners when a scenario raises an error' do
100           # given
101           error = RuntimeError.new('oops')
102           story = Story.new 'title', 'narrative' do end
103           scenario = Scenario.new story, 'scenario1' do
104           end
105           scenario_runner = ScenarioRunner.new
106           mock_listener = stub_everything('listener')
107           scenario_runner.add_listener(mock_listener)
108           world = stub_everything
109           
110           # expect
111           world.should_receive(:errors).twice.and_return([error])
112           mock_listener.should_receive(:scenario_failed).with('title', 'scenario1', error)
113           
114           # when
115           scenario_runner.run scenario, world
116           
117           # then
118           # TODO verify_all
119         end
120         
121         it 'should notify listeners when a scenario is pending' do
122           # given
123           pending_error = Spec::Example::ExamplePendingError.new('todo')
124           story = Story.new 'title', 'narrative' do end
125           scenario = Scenario.new story, 'scenario1' do
126           end
127           scenario_runner = ScenarioRunner.new
128           mock_listener = mock('listener')
129           scenario_runner.add_listener(mock_listener)
130           world = stub_everything
131           
132           # expect
133           world.should_receive(:errors).twice.and_return([pending_error])
134           mock_listener.should_receive(:scenario_started).with('title', 'scenario1')
135           mock_listener.should_receive(:scenario_pending).with('title', 'scenario1', 'todo')
136           
137           # when
138           scenario_runner.run scenario, world
139           
140           # then
141           # TODO verify_all
142         end
143       end
144     end
145   end