changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../story_helper'
2
3module 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 $answer.should == 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 end
73
74 it 'should notify listeners when a scenario succeeds' do
75 # given
76 world = stub_everything('world')
77 story = Story.new 'story', 'narrative' do end
78 scenario = Scenario.new story, 'scenario1' do
79 # succeeds
80 end
81 scenario_runner = ScenarioRunner.new
82 mock_listener1 = stub_everything('listener1')
83 mock_listener2 = stub_everything('listener2')
84 scenario_runner.add_listener(mock_listener1)
85 scenario_runner.add_listener(mock_listener2)
86
87 # expect
88 mock_listener1.should_receive(:scenario_succeeded).with('story', 'scenario1')
89 mock_listener2.should_receive(:scenario_succeeded).with('story', 'scenario1')
90
91 # when
92 scenario_runner.run(scenario, world)
93
94 # then
95 end
96
97 it 'should notify listeners ONCE when a scenario raises an error' do
98 # given
99 error = RuntimeError.new('oops')
100 story = Story.new 'title', 'narrative' do end
101 scenario = Scenario.new story, 'scenario1' do
102 end
103 scenario_runner = ScenarioRunner.new
104 mock_listener = stub_everything('listener')
105 scenario_runner.add_listener(mock_listener)
106 world = stub_everything
107
108 # expect
109 world.should_receive(:errors).twice.and_return([error, error])
110 mock_listener.should_receive(:scenario_failed).with('title', 'scenario1', error).once
111
112 # when
113 scenario_runner.run scenario, world
114
115 # then
116 end
117
118 it 'should notify listeners when a scenario is pending' do
119 # given
120 pending_error = Spec::Example::ExamplePendingError.new('todo')
121 story = Story.new 'title', 'narrative' do end
122 scenario = Scenario.new story, 'scenario1' do
123 end
124 scenario_runner = ScenarioRunner.new
125 mock_listener = mock('listener')
126 scenario_runner.add_listener(mock_listener)
127 world = stub_everything
128
129 # expect
130 world.should_receive(:errors).twice.and_return([pending_error, pending_error])
131 mock_listener.should_receive(:scenario_started).with('title', 'scenario1')
132 mock_listener.should_receive(:scenario_pending).with('title', 'scenario1', 'todo').once
133
134 # when
135 scenario_runner.run scenario, world
136
137 # then
138 end
139 end
140 end
141 end
142end