dchelimsky-rspec-stories 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/History.txt +5 -0
  2. data/License.txt +22 -0
  3. data/Manifest.txt +78 -0
  4. data/README.txt +23 -0
  5. data/Rakefile +87 -0
  6. data/init.rb +4 -0
  7. data/lib/spec/runner/formatter/story/html_formatter.rb +174 -0
  8. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +194 -0
  9. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
  10. data/lib/spec/runner/options_extensions.rb +25 -0
  11. data/lib/spec/stories.rb +11 -0
  12. data/lib/spec/story/extensions.rb +3 -0
  13. data/lib/spec/story/extensions/main.rb +86 -0
  14. data/lib/spec/story/extensions/regexp.rb +9 -0
  15. data/lib/spec/story/extensions/string.rb +9 -0
  16. data/lib/spec/story/given_scenario.rb +14 -0
  17. data/lib/spec/story/runner.rb +57 -0
  18. data/lib/spec/story/runner/plain_text_story_runner.rb +48 -0
  19. data/lib/spec/story/runner/scenario_collector.rb +18 -0
  20. data/lib/spec/story/runner/scenario_runner.rb +54 -0
  21. data/lib/spec/story/runner/story_mediator.rb +137 -0
  22. data/lib/spec/story/runner/story_parser.rb +247 -0
  23. data/lib/spec/story/runner/story_runner.rb +74 -0
  24. data/lib/spec/story/scenario.rb +14 -0
  25. data/lib/spec/story/step.rb +70 -0
  26. data/lib/spec/story/step_group.rb +89 -0
  27. data/lib/spec/story/step_mother.rb +38 -0
  28. data/lib/spec/story/story.rb +39 -0
  29. data/lib/spec/story/version.rb +15 -0
  30. data/lib/spec/story/world.rb +124 -0
  31. data/resources/rake/verify_rcov.rake +7 -0
  32. data/rspec-stories.gemspec +35 -0
  33. data/spec/spec.opts +6 -0
  34. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +135 -0
  35. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +600 -0
  36. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
  37. data/spec/spec/runner/most_recent_spec.rb +0 -0
  38. data/spec/spec/runner/options_extensions_spec.rb +31 -0
  39. data/spec/spec/runner/resources/a_bar.rb +0 -0
  40. data/spec/spec/runner/resources/a_foo.rb +0 -0
  41. data/spec/spec/runner/resources/a_spec.rb +1 -0
  42. data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
  43. data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
  44. data/spec/spec/runner_spec.rb +11 -0
  45. data/spec/spec/spec_classes.rb +133 -0
  46. data/spec/spec/story/builders.rb +46 -0
  47. data/spec/spec/story/extensions/main_spec.rb +161 -0
  48. data/spec/spec/story/extensions_spec.rb +14 -0
  49. data/spec/spec/story/given_scenario_spec.rb +27 -0
  50. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +90 -0
  51. data/spec/spec/story/runner/scenario_collector_spec.rb +27 -0
  52. data/spec/spec/story/runner/scenario_runner_spec.rb +214 -0
  53. data/spec/spec/story/runner/story_mediator_spec.rb +143 -0
  54. data/spec/spec/story/runner/story_parser_spec.rb +401 -0
  55. data/spec/spec/story/runner/story_runner_spec.rb +294 -0
  56. data/spec/spec/story/runner_spec.rb +93 -0
  57. data/spec/spec/story/scenario_spec.rb +18 -0
  58. data/spec/spec/story/step_group_spec.rb +157 -0
  59. data/spec/spec/story/step_mother_spec.rb +84 -0
  60. data/spec/spec/story/step_spec.rb +272 -0
  61. data/spec/spec/story/story_helper.rb +2 -0
  62. data/spec/spec/story/story_spec.rb +84 -0
  63. data/spec/spec/story/world_spec.rb +423 -0
  64. data/spec/spec_helper.rb +84 -0
  65. data/story_server/prototype/javascripts/builder.js +136 -0
  66. data/story_server/prototype/javascripts/controls.js +972 -0
  67. data/story_server/prototype/javascripts/dragdrop.js +976 -0
  68. data/story_server/prototype/javascripts/effects.js +1117 -0
  69. data/story_server/prototype/javascripts/prototype.js +4140 -0
  70. data/story_server/prototype/javascripts/rspec.js +149 -0
  71. data/story_server/prototype/javascripts/scriptaculous.js +58 -0
  72. data/story_server/prototype/javascripts/slider.js +276 -0
  73. data/story_server/prototype/javascripts/sound.js +55 -0
  74. data/story_server/prototype/javascripts/unittest.js +568 -0
  75. data/story_server/prototype/lib/server.rb +24 -0
  76. data/story_server/prototype/stories.html +176 -0
  77. data/story_server/prototype/stylesheets/rspec.css +136 -0
  78. data/story_server/prototype/stylesheets/test.css +90 -0
  79. metadata +154 -0
@@ -0,0 +1,401 @@
1
+ require File.dirname(__FILE__) + '/../story_helper'
2
+
3
+ module Spec
4
+ module Story
5
+ module Runner
6
+
7
+ describe StoryParser do
8
+ before(:each) do
9
+ @story_mediator = mock("story_mediator")
10
+ @parser = StoryParser.new(@story_mediator)
11
+ end
12
+
13
+ it "should parse no lines" do
14
+ @parser.parse([])
15
+ end
16
+
17
+ it "should ignore text before the first Story: begins" do
18
+ @story_mediator.should_not_receive(:create_scenario)
19
+ @story_mediator.should_not_receive(:create_given)
20
+ @story_mediator.should_not_receive(:create_when)
21
+ @story_mediator.should_not_receive(:create_then)
22
+ @story_mediator.should_receive(:create_story).with("simple addition", "")
23
+ @parser.parse(["Here is a bunch of text", "about a calculator and all the things", "that it will do", "Story: simple addition"])
24
+ end
25
+
26
+ it "should create a story" do
27
+ @story_mediator.should_receive(:create_story).with("simple addition", "")
28
+ @parser.parse(["Story: simple addition"])
29
+ end
30
+
31
+ it "should create a story when line has leading spaces" do
32
+ @story_mediator.should_receive(:create_story).with("simple addition", "")
33
+ @parser.parse([" Story: simple addition"])
34
+ end
35
+
36
+ it "should add a one line narrative to the story" do
37
+ @story_mediator.should_receive(:create_story).with("simple addition","narrative")
38
+ @parser.parse(["Story: simple addition","narrative"])
39
+ end
40
+
41
+ it "should add a multi line narrative to the story" do
42
+ @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2\nline 3")
43
+ @parser.parse(["Story: simple addition","narrative line 1", "line 2", "line 3"])
44
+ end
45
+
46
+ it "should exclude blank lines from the narrative" do
47
+ @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2")
48
+ @parser.parse(["Story: simple addition","narrative line 1", "", "line 2"])
49
+ end
50
+
51
+ it "should exclude Scenario from the narrative" do
52
+ @story_mediator.should_receive(:create_story).with("simple addition","narrative line 1\nline 2")
53
+ @story_mediator.should_receive(:create_scenario)
54
+ @parser.parse(["Story: simple addition","narrative line 1", "line 2", "Scenario: add one plus one"])
55
+ end
56
+
57
+ end
58
+
59
+ describe StoryParser, "in Story state" do
60
+ before(:each) do
61
+ @story_mediator = mock("story_mediator")
62
+ @parser = StoryParser.new(@story_mediator)
63
+ @story_mediator.stub!(:create_story)
64
+ end
65
+
66
+ it "should create a second Story for Story" do
67
+ @story_mediator.should_receive(:create_story).with("number two","")
68
+ @parser.parse(["Story: s", "Story: number two"])
69
+ end
70
+
71
+ it "should include And in the narrative" do
72
+ @story_mediator.should_receive(:create_story).with("s","And foo")
73
+ @story_mediator.should_receive(:create_scenario).with("bar")
74
+ @parser.parse(["Story: s", "And foo", "Scenario: bar"])
75
+ end
76
+
77
+ it "should create a Scenario for Scenario" do
78
+ @story_mediator.should_receive(:create_scenario).with("number two")
79
+ @parser.parse(["Story: s", "Scenario: number two"])
80
+ end
81
+
82
+ it "should include Given in the narrative" do
83
+ @story_mediator.should_receive(:create_story).with("s","Given foo")
84
+ @story_mediator.should_receive(:create_scenario).with("bar")
85
+ @parser.parse(["Story: s", "Given foo", "Scenario: bar"])
86
+ end
87
+
88
+ it "should include Given: in the narrative" do
89
+ @story_mediator.should_receive(:create_story).with("s","Given: foo")
90
+ @story_mediator.should_receive(:create_scenario).with("bar")
91
+ @parser.parse(["Story: s", "Given: foo", "Scenario: bar"])
92
+ end
93
+
94
+ it "should include When in the narrative" do
95
+ @story_mediator.should_receive(:create_story).with("s","When foo")
96
+ @story_mediator.should_receive(:create_scenario).with("bar")
97
+ @parser.parse(["Story: s", "When foo", "Scenario: bar"])
98
+ end
99
+
100
+ it "should include Then in the narrative" do
101
+ @story_mediator.should_receive(:create_story).with("s","Then foo")
102
+ @story_mediator.should_receive(:create_scenario).with("bar")
103
+ @parser.parse(["Story: s", "Then foo", "Scenario: bar"])
104
+ end
105
+
106
+ it "should include other in the story" do
107
+ @story_mediator.should_receive(:create_story).with("s","narrative")
108
+ @parser.parse(["Story: s", "narrative"])
109
+ end
110
+ end
111
+
112
+ describe StoryParser, "in Scenario state" do
113
+ before(:each) do
114
+ @story_mediator = mock("story_mediator")
115
+ @parser = StoryParser.new(@story_mediator)
116
+ @story_mediator.stub!(:create_story)
117
+ @story_mediator.stub!(:create_scenario)
118
+ end
119
+
120
+ it "should create a Story for Story" do
121
+ @story_mediator.should_receive(:create_story).with("number two","")
122
+ @parser.parse(["Story: s", "Scenario: s", "Story: number two"])
123
+ end
124
+
125
+ it "should create a Scenario for Scenario" do
126
+ @story_mediator.should_receive(:create_scenario).with("number two")
127
+ @parser.parse(["Story: s", "Scenario: s", "Scenario: number two"])
128
+ end
129
+
130
+ it "should raise for And" do
131
+ lambda {
132
+ @parser.parse(["Story: s", "Scenario: s", "And second"])
133
+ }.should raise_error(IllegalStepError, /^Illegal attempt to create a And after a Scenario/)
134
+ end
135
+
136
+ it "should create a Given for Given" do
137
+ @story_mediator.should_receive(:create_given).with("gift")
138
+ @parser.parse(["Story: s", "Scenario: s", "Given gift"])
139
+ end
140
+
141
+ it "should create a Given for Given:" do
142
+ @story_mediator.should_receive(:create_given).with("gift")
143
+ @parser.parse(["Story: s", "Scenario: s", "Given: gift"])
144
+ end
145
+
146
+ it "should create a GivenScenario for GivenScenario" do
147
+ @story_mediator.should_receive(:create_given_scenario).with("previous")
148
+ @parser.parse(["Story: s", "Scenario: s", "GivenScenario previous"])
149
+ end
150
+
151
+ it "should create a GivenScenario for GivenScenario:" do
152
+ @story_mediator.should_receive(:create_given_scenario).with("previous")
153
+ @parser.parse(["Story: s", "Scenario: s", "GivenScenario: previous"])
154
+ end
155
+
156
+ it "should transition to Given state after GivenScenario" do
157
+ @story_mediator.stub!(:create_given_scenario)
158
+ @parser.parse(["Story: s", "Scenario: s", "GivenScenario previous"])
159
+ @parser.instance_eval{@state}.should be_an_instance_of(StoryParser::GivenState)
160
+ end
161
+
162
+ it "should transition to Given state after GivenScenario:" do
163
+ @story_mediator.stub!(:create_given_scenario)
164
+ @parser.parse(["Story: s", "Scenario: s", "GivenScenario: previous"])
165
+ @parser.instance_eval{@state}.should be_an_instance_of(StoryParser::GivenState)
166
+ end
167
+
168
+ it "should create a When for When" do
169
+ @story_mediator.should_receive(:create_when).with("ever")
170
+ @parser.parse(["Story: s", "Scenario: s", "When ever"])
171
+ end
172
+
173
+ it "should create a When for When:" do
174
+ @story_mediator.should_receive(:create_when).with("ever")
175
+ @parser.parse(["Story: s", "Scenario: s", "When: ever"])
176
+ end
177
+
178
+ it "should create a Then for Then" do
179
+ @story_mediator.should_receive(:create_then).with("and there")
180
+ @parser.parse(["Story: s", "Scenario: s", "Then and there"])
181
+ end
182
+
183
+ it "should create a Then for Then:" do
184
+ @story_mediator.should_receive(:create_then).with("and there")
185
+ @parser.parse(["Story: s", "Scenario: s", "Then: and there"])
186
+ end
187
+
188
+ it "should ignore other" do
189
+ @parser.parse(["Story: s", "Scenario: s", "this is ignored"])
190
+ end
191
+ end
192
+
193
+ describe StoryParser, "in Given state" do
194
+ before(:each) do
195
+ @story_mediator = mock("story_mediator")
196
+ @parser = StoryParser.new(@story_mediator)
197
+ @story_mediator.stub!(:create_story)
198
+ @story_mediator.stub!(:create_scenario)
199
+ @story_mediator.should_receive(:create_given).with("first")
200
+ end
201
+
202
+ it "should create a Story for Story" do
203
+ @story_mediator.should_receive(:create_story).with("number two","")
204
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "Story: number two"])
205
+ end
206
+
207
+ it "should create a Scenario for Scenario" do
208
+ @story_mediator.should_receive(:create_scenario).with("number two")
209
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "Scenario: number two"])
210
+ end
211
+
212
+ it "should create a second Given for Given" do
213
+ @story_mediator.should_receive(:create_given).with("second")
214
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "Given second"])
215
+ end
216
+
217
+ it "should create a second Given for And" do
218
+ @story_mediator.should_receive(:create_given).with("second")
219
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "And second"])
220
+ end
221
+
222
+ it "should create a second Given for And:" do
223
+ @story_mediator.should_receive(:create_given).with("second")
224
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "And: second"])
225
+ end
226
+
227
+ it "should create a When for When" do
228
+ @story_mediator.should_receive(:create_when).with("ever")
229
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When ever"])
230
+ end
231
+
232
+ it "should create a When for When:" do
233
+ @story_mediator.should_receive(:create_when).with("ever")
234
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When: ever"])
235
+ end
236
+
237
+ it "should create a Then for Then" do
238
+ @story_mediator.should_receive(:create_then).with("and there")
239
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "Then and there"])
240
+ end
241
+
242
+ it "should create a Then for Then:" do
243
+ @story_mediator.should_receive(:create_then).with("and there")
244
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "Then: and there"])
245
+ end
246
+
247
+ it "should ignore lines beginning with '#'" do
248
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "#this is ignored"])
249
+ end
250
+
251
+ it "should not ignore lines beginning with non-keywords" do
252
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
253
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "this is not ignored"])
254
+ end
255
+
256
+ end
257
+
258
+ describe StoryParser, "in When state" do
259
+ before(:each) do
260
+ @story_mediator = mock("story_mediator")
261
+ @parser = StoryParser.new(@story_mediator)
262
+ @story_mediator.stub!(:create_story)
263
+ @story_mediator.stub!(:create_scenario)
264
+ @story_mediator.should_receive(:create_given).with("first")
265
+ @story_mediator.should_receive(:create_when).with("else")
266
+ end
267
+
268
+ it "should create a Story for Story" do
269
+ @story_mediator.should_receive(:create_story).with("number two","")
270
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When: else", "Story: number two"])
271
+ end
272
+
273
+ it "should create a Scenario for Scenario" do
274
+ @story_mediator.should_receive(:create_scenario).with("number two")
275
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Scenario: number two"])
276
+ end
277
+
278
+ it "should create Given for Given" do
279
+ @story_mediator.should_receive(:create_given).with("second")
280
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Given second"])
281
+ end
282
+
283
+ it "should create Given for Given:" do
284
+ @story_mediator.should_receive(:create_given).with("second")
285
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Given: second"])
286
+ end
287
+
288
+ it "should create a second When for When" do
289
+ @story_mediator.should_receive(:create_when).with("ever")
290
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "When ever"])
291
+ end
292
+
293
+ it "should create a second When for When:" do
294
+ @story_mediator.should_receive(:create_when).with("ever")
295
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "When: ever"])
296
+ end
297
+
298
+ it "should create a second When for And" do
299
+ @story_mediator.should_receive(:create_when).with("ever")
300
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "And ever"])
301
+ end
302
+
303
+ it "should create a second When for And:" do
304
+ @story_mediator.should_receive(:create_when).with("ever")
305
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "And: ever"])
306
+ end
307
+
308
+ it "should create a Then for Then" do
309
+ @story_mediator.should_receive(:create_then).with("and there")
310
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then and there"])
311
+ end
312
+
313
+ it "should create a Then for Then:" do
314
+ @story_mediator.should_receive(:create_then).with("and there")
315
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: and there"])
316
+ end
317
+
318
+ it "should ignore lines beginning with '#'" do
319
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "#this is ignored"])
320
+ end
321
+
322
+ it "should not ignore lines beginning with non-keywords" do
323
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
324
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When else", "this is not ignored"])
325
+ end
326
+ end
327
+
328
+ describe StoryParser, "in Then state" do
329
+ before(:each) do
330
+ @story_mediator = mock("story_mediator")
331
+ @parser = StoryParser.new(@story_mediator)
332
+ @story_mediator.stub!(:create_story)
333
+ @story_mediator.stub!(:create_scenario)
334
+ @story_mediator.should_receive(:create_given).with("first")
335
+ @story_mediator.should_receive(:create_when).with("else")
336
+ @story_mediator.should_receive(:create_then).with("what")
337
+ end
338
+
339
+ it "should create a Story for Story" do
340
+ @story_mediator.should_receive(:create_story).with("number two","")
341
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Story: number two"])
342
+ end
343
+
344
+ it "should create a Scenario for Scenario" do
345
+ @story_mediator.should_receive(:create_scenario).with("number two")
346
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Scenario: number two"])
347
+ end
348
+
349
+ it "should create Given for Given" do
350
+ @story_mediator.should_receive(:create_given).with("second")
351
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Given second"])
352
+ end
353
+
354
+ it "should create Given for Given:" do
355
+ @story_mediator.should_receive(:create_given).with("second")
356
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "Given: second"])
357
+ end
358
+
359
+ it "should create When for When" do
360
+ @story_mediator.should_receive(:create_when).with("ever")
361
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "When ever"])
362
+ end
363
+
364
+ it "should create When for When:" do
365
+ @story_mediator.should_receive(:create_when).with("ever")
366
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "When: ever"])
367
+ end
368
+
369
+ it "should create a Then for Then" do
370
+ @story_mediator.should_receive(:create_then).with("and there")
371
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "Then and there"])
372
+ end
373
+
374
+ it "should create a Then for Then:" do
375
+ @story_mediator.should_receive(:create_then).with("and there")
376
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "Then: and there"])
377
+ end
378
+
379
+ it "should create a second Then for And" do
380
+ @story_mediator.should_receive(:create_then).with("ever")
381
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "And ever"])
382
+ end
383
+
384
+ it "should create a second Then for And:" do
385
+ @story_mediator.should_receive(:create_then).with("ever")
386
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When: else", "Then: what", "And: ever"])
387
+ end
388
+
389
+
390
+ it "should ignore lines beginning with '#'" do
391
+ @parser.parse(["Story: s", "Scenario: s", "Given first", "When else", "Then what", "#this is ignored"])
392
+ end
393
+
394
+ it "should not ignore lines beginning with non-keywords" do
395
+ @story_mediator.should_receive(:add_to_last).with("\nthis is not ignored")
396
+ @parser.parse(["Story: s", "Scenario: s", "Given: first", "When else", "Then what", "this is not ignored"])
397
+ end
398
+ end
399
+ end
400
+ end
401
+ end
@@ -0,0 +1,294 @@
1
+ require File.dirname(__FILE__) + '/../story_helper'
2
+
3
+ module Spec
4
+ module Story
5
+ module Runner
6
+ describe StoryRunner do
7
+ it 'should collect all the stories' do
8
+ # given
9
+ story_runner = StoryRunner.new(stub('scenario_runner'))
10
+
11
+ # when
12
+ story_runner.Story 'title1', 'narrative1' do end
13
+ story_runner.Story 'title2', 'narrative2' do end
14
+ stories = story_runner.stories
15
+
16
+ # then
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'
22
+ end
23
+
24
+ it 'should gather all the scenarios in the stories' do
25
+ # given
26
+ story_runner = StoryRunner.new(stub('scenario_runner'))
27
+
28
+ # when
29
+ story_runner.Story "story1", "narrative1" do
30
+ Scenario "scenario1" do end
31
+ Scenario "scenario2" do end
32
+ end
33
+ story_runner.Story "story2", "narrative2" do
34
+ Scenario "scenario3" do end
35
+ end
36
+ scenarios = story_runner.scenarios
37
+
38
+ # then
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'
43
+ end
44
+
45
+ # captures worlds passed into a ScenarioRunner
46
+ class ScenarioWorldCatcher
47
+ attr_accessor :worlds
48
+ def run(scenario, world)
49
+ (@worlds ||= []) << world
50
+ end
51
+ end
52
+
53
+ it 'should run each scenario in a separate object' do
54
+ # given
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
60
+ end
61
+
62
+ # when
63
+ story_runner.run_stories
64
+
65
+ # then
66
+ worlds = scenario_world_catcher.worlds
67
+ scenario_world_catcher.should have(2).worlds
68
+ worlds[0].should_not == worlds[1]
69
+ end
70
+
71
+ it "should return false if the scenario runner returns false ever" do
72
+ #given
73
+ stub_scenario_runner = stub_everything
74
+ story_runner = StoryRunner.new(stub_scenario_runner)
75
+ story_runner.Story 'story', 'narrative' do
76
+ Scenario 'scenario1' do end
77
+ Scenario 'scenario2' do end
78
+ end
79
+
80
+ # expect
81
+ stub_scenario_runner.should_receive(:run).once.and_return(false,true)
82
+
83
+ # when
84
+ success = story_runner.run_stories
85
+
86
+ #then
87
+ success.should == false
88
+ end
89
+
90
+ it "should return true if the scenario runner returns true for all scenarios" do
91
+ #given
92
+ stub_scenario_runner = stub_everything
93
+ story_runner = StoryRunner.new(stub_scenario_runner)
94
+ story_runner.Story 'story', 'narrative' do
95
+ Scenario 'scenario1' do end
96
+ Scenario 'scenario2' do end
97
+ end
98
+
99
+ # expect
100
+ stub_scenario_runner.should_receive(:run).once.and_return(true,true)
101
+
102
+ # when
103
+ success = story_runner.run_stories
104
+
105
+ #then
106
+ success.should == true
107
+ end
108
+
109
+ it 'should use the provided world creator to create worlds' do
110
+ # given
111
+ stub_scenario_runner = stub_everything
112
+ mock_world_creator = mock('world creator')
113
+ story_runner = StoryRunner.new(stub_scenario_runner, mock_world_creator)
114
+ story_runner.Story 'story', 'narrative' do
115
+ Scenario 'scenario1' do end
116
+ Scenario 'scenario2' do end
117
+ end
118
+
119
+ # expect
120
+ mock_world_creator.should_receive(:create).twice
121
+
122
+ # when
123
+ story_runner.run_stories
124
+
125
+ # then
126
+ end
127
+
128
+ it 'should notify listeners of the scenario count when the run starts' do
129
+ # given
130
+ story_runner = StoryRunner.new(stub_everything)
131
+ mock_listener1 = stub_everything('listener1')
132
+ mock_listener2 = stub_everything('listener2')
133
+ story_runner.add_listener(mock_listener1)
134
+ story_runner.add_listener(mock_listener2)
135
+
136
+ story_runner.Story 'story1', 'narrative1' do
137
+ Scenario 'scenario1' do end
138
+ end
139
+ story_runner.Story 'story2', 'narrative2' do
140
+ Scenario 'scenario2' do end
141
+ Scenario 'scenario3' do end
142
+ end
143
+
144
+ # expect
145
+ mock_listener1.should_receive(:run_started).with(3)
146
+ mock_listener2.should_receive(:run_started).with(3)
147
+
148
+ # when
149
+ story_runner.run_stories
150
+
151
+ # then
152
+ end
153
+
154
+ it 'should notify listeners when a story starts' do
155
+ # given
156
+ story_runner = StoryRunner.new(stub_everything)
157
+ mock_listener1 = stub_everything('listener1')
158
+ mock_listener2 = stub_everything('listener2')
159
+ story_runner.add_listener(mock_listener1)
160
+ story_runner.add_listener(mock_listener2)
161
+
162
+ story_runner.Story 'story1', 'narrative1' do
163
+ Scenario 'scenario1' do end
164
+ end
165
+ story_runner.Story 'story2', 'narrative2' do
166
+ Scenario 'scenario2' do end
167
+ Scenario 'scenario3' do end
168
+ end
169
+
170
+ # expect
171
+ mock_listener1.should_receive(:story_started).with('story1', 'narrative1')
172
+ mock_listener1.should_receive(:story_ended).with('story1', 'narrative1')
173
+ mock_listener2.should_receive(:story_started).with('story2', 'narrative2')
174
+ mock_listener2.should_receive(:story_ended).with('story2', 'narrative2')
175
+
176
+ # when
177
+ story_runner.run_stories
178
+
179
+ # then
180
+ end
181
+
182
+ it 'should notify listeners when the run ends' do
183
+ # given
184
+ story_runner = StoryRunner.new(stub_everything)
185
+ mock_listener1 = stub_everything('listener1')
186
+ mock_listener2 = stub_everything('listener2')
187
+ story_runner.add_listener mock_listener1
188
+ story_runner.add_listener mock_listener2
189
+ story_runner.Story 'story1', 'narrative1' do
190
+ Scenario 'scenario1' do end
191
+ end
192
+
193
+ # expect
194
+ mock_listener1.should_receive(:run_ended)
195
+ mock_listener2.should_receive(:run_ended)
196
+
197
+ # when
198
+ story_runner.run_stories
199
+
200
+ # then
201
+ end
202
+
203
+ it 'should run a story in an instance of a specified class' do
204
+ # given
205
+ scenario_world_catcher = ScenarioWorldCatcher.new
206
+ story_runner = StoryRunner.new(scenario_world_catcher)
207
+ story_runner.Story 'title', 'narrative', :type => String do
208
+ Scenario 'scenario' do end
209
+ end
210
+
211
+ # when
212
+ story_runner.run_stories
213
+
214
+ # then
215
+ scenario_world_catcher.worlds[0].should be_kind_of(String)
216
+ scenario_world_catcher.worlds[0].should be_kind_of(World)
217
+ end
218
+
219
+ it 'should pass initialization params through to the constructed instance' do
220
+ # given
221
+ scenario_world_catcher = ScenarioWorldCatcher.new
222
+ story_runner = StoryRunner.new(scenario_world_catcher)
223
+ story_runner.Story 'title', 'narrative', :type => Array, :args => [3] do
224
+ Scenario 'scenario' do end
225
+ end
226
+
227
+ # when
228
+ story_runner.run_stories
229
+
230
+ # then
231
+ scenario_world_catcher.worlds[0].should be_kind_of(Array)
232
+ scenario_world_catcher.worlds[0].size.should == 3
233
+ end
234
+
235
+ it 'should find a scenario in the current story by name' do
236
+ # given
237
+ story_runner = StoryRunner.new(ScenarioRunner.new)
238
+ scenario = nil
239
+
240
+ story_runner.Story 'title', 'narrative' do
241
+ Scenario 'first scenario' do
242
+ end
243
+ Scenario 'second scenario' do
244
+ scenario = StoryRunner.scenario_from_current_story 'first scenario'
245
+ end
246
+ end
247
+
248
+ # when
249
+ story_runner.run_stories
250
+
251
+ # then
252
+ scenario.name.should == 'first scenario'
253
+ end
254
+
255
+ it "should clean the steps between stories" do
256
+ #given
257
+ story_runner = StoryRunner.new(ScenarioRunner.new)
258
+ result = mock 'result'
259
+
260
+ step1 = Step.new('step') do
261
+ result.one
262
+ end
263
+ steps1 = StepGroup.new
264
+ steps1.add :when, step1
265
+
266
+ story_runner.Story 'title', 'narrative', :steps_for => steps1 do
267
+ Scenario 'first scenario' do
268
+ When 'step'
269
+ end
270
+ end
271
+
272
+ step2 = Step.new('step') do
273
+ result.two
274
+ end
275
+ steps2 = StepGroup.new
276
+ steps2.add :when, step2
277
+
278
+ story_runner.Story 'title2', 'narrative', :steps_for => steps2 do
279
+ Scenario 'second scenario' do
280
+ When 'step'
281
+ end
282
+ end
283
+
284
+ #then
285
+ result.should_receive(:one)
286
+ result.should_receive(:two)
287
+
288
+ #when
289
+ story_runner.run_stories
290
+ end
291
+ end
292
+ end
293
+ end
294
+ end