summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go
blob: a41437922379cb717d75969495739ae33568af99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
package specrunner_test

import (
	. "github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/internal/spec_iterator"
	. "github.com/onsi/ginkgo/internal/specrunner"
	"github.com/onsi/ginkgo/types"
	. "github.com/onsi/gomega"

	"github.com/onsi/ginkgo/config"
	"github.com/onsi/ginkgo/internal/codelocation"
	"github.com/onsi/ginkgo/internal/containernode"
	Failer "github.com/onsi/ginkgo/internal/failer"
	"github.com/onsi/ginkgo/internal/leafnodes"
	"github.com/onsi/ginkgo/internal/spec"
	Writer "github.com/onsi/ginkgo/internal/writer"
	"github.com/onsi/ginkgo/reporters"
)

var noneFlag = types.FlagTypeNone
var pendingFlag = types.FlagTypePending

var _ = Describe("Spec Runner", func() {
	var (
		reporter1 *reporters.FakeReporter
		reporter2 *reporters.FakeReporter
		failer    *Failer.Failer
		writer    *Writer.FakeGinkgoWriter

		thingsThatRan []string

		runner *SpecRunner
	)

	newBefSuite := func(text string, fail bool) leafnodes.SuiteNode {
		return leafnodes.NewBeforeSuiteNode(func() {
			writer.AddEvent(text)
			thingsThatRan = append(thingsThatRan, text)
			if fail {
				failer.Fail(text, codelocation.New(0))
			}
		}, codelocation.New(0), 0, failer)
	}

	newAftSuite := func(text string, fail bool) leafnodes.SuiteNode {
		return leafnodes.NewAfterSuiteNode(func() {
			writer.AddEvent(text)
			thingsThatRan = append(thingsThatRan, text)
			if fail {
				failer.Fail(text, codelocation.New(0))
			}
		}, codelocation.New(0), 0, failer)
	}

	newSpec := func(text string, flag types.FlagType, fail bool) *spec.Spec {
		subject := leafnodes.NewItNode(text, func() {
			writer.AddEvent(text)
			thingsThatRan = append(thingsThatRan, text)
			if fail {
				failer.Fail(text, codelocation.New(0))
			}
		}, flag, codelocation.New(0), 0, failer, 0)

		return spec.New(subject, []*containernode.ContainerNode{}, false)
	}

	newFlakySpec := func(text string, flag types.FlagType, failures int) *spec.Spec {
		runs := 0
		subject := leafnodes.NewItNode(text, func() {
			writer.AddEvent(text)
			thingsThatRan = append(thingsThatRan, text)
			runs++
			if runs < failures {
				failer.Fail(text, codelocation.New(0))
			}
		}, flag, codelocation.New(0), 0, failer, 0)

		return spec.New(subject, []*containernode.ContainerNode{}, false)
	}

	newSpecWithBody := func(text string, body interface{}) *spec.Spec {
		subject := leafnodes.NewItNode(text, body, noneFlag, codelocation.New(0), 0, failer, 0)

		return spec.New(subject, []*containernode.ContainerNode{}, false)
	}

	newRunner := func(config config.GinkgoConfigType, beforeSuiteNode leafnodes.SuiteNode, afterSuiteNode leafnodes.SuiteNode, specs ...*spec.Spec) *SpecRunner {
		iterator := spec_iterator.NewSerialIterator(specs)
		return New("description", beforeSuiteNode, iterator, afterSuiteNode, []reporters.Reporter{reporter1, reporter2}, writer, config)
	}

	BeforeEach(func() {
		reporter1 = reporters.NewFakeReporter()
		reporter2 = reporters.NewFakeReporter()
		writer = Writer.NewFake()
		failer = Failer.New()

		thingsThatRan = []string{}
	})

	Describe("Running and Reporting", func() {
		var specA, pendingSpec, anotherPendingSpec, failedSpec, specB, skippedSpec *spec.Spec
		var willRunCalls, didCompleteCalls []string
		var conf config.GinkgoConfigType

		JustBeforeEach(func() {
			willRunCalls = []string{}
			didCompleteCalls = []string{}
			specA = newSpec("spec A", noneFlag, false)
			pendingSpec = newSpec("pending spec", pendingFlag, false)
			anotherPendingSpec = newSpec("another pending spec", pendingFlag, false)
			failedSpec = newSpec("failed spec", noneFlag, true)
			specB = newSpec("spec B", noneFlag, false)
			skippedSpec = newSpec("skipped spec", noneFlag, false)
			skippedSpec.Skip()

			reporter1.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				willRunCalls = append(willRunCalls, "Reporter1")
			}
			reporter2.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				willRunCalls = append(willRunCalls, "Reporter2")
			}

			reporter1.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				didCompleteCalls = append(didCompleteCalls, "Reporter1")
			}
			reporter2.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				didCompleteCalls = append(didCompleteCalls, "Reporter2")
			}

			runner = newRunner(conf, newBefSuite("BefSuite", false), newAftSuite("AftSuite", false), specA, pendingSpec, anotherPendingSpec, failedSpec, specB, skippedSpec)
			runner.Run()
		})

		BeforeEach(func() {
			conf = config.GinkgoConfigType{RandomSeed: 17}
		})

		It("should skip skipped/pending tests", func() {
			Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "spec A", "failed spec", "spec B", "AftSuite"}))
		})

		It("should report to any attached reporters", func() {
			Ω(reporter1.Config).Should(Equal(reporter2.Config))
			Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
			Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
			Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
			Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
			Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
			Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
		})

		It("should report that a spec did end in reverse order", func() {
			Ω(willRunCalls[0:4]).Should(Equal([]string{"Reporter1", "Reporter2", "Reporter1", "Reporter2"}))
			Ω(didCompleteCalls[0:4]).Should(Equal([]string{"Reporter2", "Reporter1", "Reporter2", "Reporter1"}))
		})

		It("should report the passed in config", func() {
			Ω(reporter1.Config.RandomSeed).Should(BeNumerically("==", 17))
		})

		It("should report the beginning of the suite", func() {
			Ω(reporter1.BeginSummary.SuiteDescription).Should(Equal("description"))
			Ω(reporter1.BeginSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
			Ω(reporter1.BeginSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
			Ω(reporter1.BeginSummary.NumberOfTotalSpecs).Should(Equal(6))
			Ω(reporter1.BeginSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
			Ω(reporter1.BeginSummary.NumberOfPendingSpecs).Should(Equal(-1))
			Ω(reporter1.BeginSummary.NumberOfSkippedSpecs).Should(Equal(-1))
		})

		It("should report the end of the suite", func() {
			Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
			Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
			Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
			Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
			Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
			Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
			Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(2))
			Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
			Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(2))
			Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(1))
		})

		Context("when told to perform a dry run", func() {
			BeforeEach(func() {
				conf.DryRun = true
			})

			It("should report to the reporters", func() {
				Ω(reporter1.Config).Should(Equal(reporter2.Config))
				Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
				Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
				Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
				Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
				Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
				Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
			})

			It("should not actually run anything", func() {
				Ω(thingsThatRan).Should(BeEmpty())
			})

			It("report before and after suites as passed", func() {
				Ω(reporter1.BeforeSuiteSummary.State).Should(Equal(types.SpecStatePassed))
				Ω(reporter1.AfterSuiteSummary.State).Should(Equal(types.SpecStatePassed))
			})

			It("should report specs as passed", func() {
				summaries := reporter1.SpecSummaries
				Ω(summaries).Should(HaveLen(6))
				Ω(summaries[0].ComponentTexts).Should(ContainElement("spec A"))
				Ω(summaries[0].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[1].ComponentTexts).Should(ContainElement("pending spec"))
				Ω(summaries[1].State).Should(Equal(types.SpecStatePending))
				Ω(summaries[2].ComponentTexts).Should(ContainElement("another pending spec"))
				Ω(summaries[2].State).Should(Equal(types.SpecStatePending))
				Ω(summaries[3].ComponentTexts).Should(ContainElement("failed spec"))
				Ω(summaries[3].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[4].ComponentTexts).Should(ContainElement("spec B"))
				Ω(summaries[4].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[5].ComponentTexts).Should(ContainElement("skipped spec"))
				Ω(summaries[5].State).Should(Equal(types.SpecStateSkipped))
			})

			It("should report the end of the suite", func() {
				Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
				Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
				Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
				Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
				Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
				Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(2))
				Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
				Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(0))
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
			})

			It("should not report a slow test", func() {
				summaries := reporter1.SpecSummaries
				for _, s := range summaries {
					Expect(s.RunTime).To(BeZero())
				}
			})
		})
	})

	Describe("reporting on specs", func() {
		var proceed chan bool
		var ready chan bool
		var finished chan bool
		BeforeEach(func() {
			ready = make(chan bool)
			proceed = make(chan bool)
			finished = make(chan bool)
			skippedSpec := newSpec("SKIP", noneFlag, false)
			skippedSpec.Skip()

			runner = newRunner(
				config.GinkgoConfigType{},
				newBefSuite("BefSuite", false),
				newAftSuite("AftSuite", false),
				skippedSpec,
				newSpec("PENDING", pendingFlag, false),
				newSpecWithBody("RUN", func() {
					close(ready)
					<-proceed
				}),
			)
			go func() {
				runner.Run()
				close(finished)
			}()
		})

		It("should report about pending/skipped specs", func() {
			<-ready
			Ω(reporter1.SpecWillRunSummaries).Should(HaveLen(3))

			Ω(reporter1.SpecWillRunSummaries[0].ComponentTexts[0]).Should(Equal("SKIP"))
			Ω(reporter1.SpecWillRunSummaries[1].ComponentTexts[0]).Should(Equal("PENDING"))
			Ω(reporter1.SpecWillRunSummaries[2].ComponentTexts[0]).Should(Equal("RUN"))

			Ω(reporter1.SpecSummaries[0].ComponentTexts[0]).Should(Equal("SKIP"))
			Ω(reporter1.SpecSummaries[1].ComponentTexts[0]).Should(Equal("PENDING"))
			Ω(reporter1.SpecSummaries).Should(HaveLen(2))

			close(proceed)
			<-finished

			Ω(reporter1.SpecSummaries).Should(HaveLen(3))
			Ω(reporter1.SpecSummaries[2].ComponentTexts[0]).Should(Equal("RUN"))
		})
	})

	Describe("Running and Reporting when there's flakes", func() {
		var specA, pendingSpec, flakySpec, failedSpec, specB, skippedSpec *spec.Spec
		var willRunCalls, didCompleteCalls []string
		var conf config.GinkgoConfigType
		var failedSpecFlag = noneFlag

		JustBeforeEach(func() {
			willRunCalls = []string{}
			didCompleteCalls = []string{}
			specA = newSpec("spec A", noneFlag, false)
			pendingSpec = newSpec("pending spec", pendingFlag, false)
			flakySpec = newFlakySpec("flaky spec", noneFlag, 3)
			failedSpec = newSpec("failed spec", failedSpecFlag, true)
			specB = newSpec("spec B", noneFlag, false)
			skippedSpec = newSpec("skipped spec", noneFlag, false)
			skippedSpec.Skip()

			reporter1.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				willRunCalls = append(willRunCalls, "Reporter1")
			}
			reporter2.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				willRunCalls = append(willRunCalls, "Reporter2")
			}

			reporter1.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				didCompleteCalls = append(didCompleteCalls, "Reporter1")
			}
			reporter2.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				didCompleteCalls = append(didCompleteCalls, "Reporter2")
			}

			runner = newRunner(conf, newBefSuite("BefSuite", false), newAftSuite("AftSuite", false), specA, pendingSpec, flakySpec, failedSpec, specB, skippedSpec)
			runner.Run()
		})

		BeforeEach(func() {
			failedSpecFlag = noneFlag
			conf = config.GinkgoConfigType{
				RandomSeed:    17,
				FlakeAttempts: 5,
			}
		})

		It("should skip skipped/pending tests", func() {
			Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "spec A", "flaky spec", "flaky spec", "flaky spec", "failed spec", "failed spec", "failed spec", "failed spec", "failed spec", "spec B", "AftSuite"}))
		})

		It("should report to any attached reporters", func() {
			Ω(reporter1.Config).Should(Equal(reporter2.Config))
			Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
			Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
			Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
			Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
			Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
			Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
		})

		It("should report that a spec did end in reverse order", func() {
			Ω(willRunCalls[0:4]).Should(Equal([]string{"Reporter1", "Reporter2", "Reporter1", "Reporter2"}))
			Ω(didCompleteCalls[0:4]).Should(Equal([]string{"Reporter2", "Reporter1", "Reporter2", "Reporter1"}))
		})

		It("should report the passed in config", func() {
			Ω(reporter1.Config.RandomSeed).Should(BeNumerically("==", 17))
		})

		It("should report the beginning of the suite", func() {
			Ω(reporter1.BeginSummary.SuiteDescription).Should(Equal("description"))
			Ω(reporter1.BeginSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
			Ω(reporter1.BeginSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
			Ω(reporter1.BeginSummary.NumberOfTotalSpecs).Should(Equal(6))
			Ω(reporter1.BeginSummary.NumberOfSpecsThatWillBeRun).Should(Equal(4))
			Ω(reporter1.BeginSummary.NumberOfPendingSpecs).Should(Equal(-1))
			Ω(reporter1.BeginSummary.NumberOfSkippedSpecs).Should(Equal(-1))
		})

		It("should report the end of the suite", func() {
			Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
			Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
			Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
			Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
			Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
			Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(4))
			Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(1))
			Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
			Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(3))
			Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(1))
			Ω(reporter1.EndSummary.NumberOfFlakedSpecs).Should(Equal(1))
		})

		Context("when nothing fails", func() {
			BeforeEach(func() {
				failedSpecFlag = pendingFlag
			})

			It("the suite should pass even with flakes", func() {
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
				Ω(reporter1.EndSummary.NumberOfFlakedSpecs).Should(Equal(1))
			})
		})

		Context("when told to perform a dry run", func() {
			BeforeEach(func() {
				conf.DryRun = true
			})

			It("should report to the reporters", func() {
				Ω(reporter1.Config).Should(Equal(reporter2.Config))
				Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
				Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
				Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
				Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
				Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
				Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
			})

			It("should not actually run anything", func() {
				Ω(thingsThatRan).Should(BeEmpty())
			})

			It("report before and after suites as passed", func() {
				Ω(reporter1.BeforeSuiteSummary.State).Should(Equal(types.SpecStatePassed))
				Ω(reporter1.AfterSuiteSummary.State).Should(Equal(types.SpecStatePassed))
			})

			It("should report specs as passed", func() {
				summaries := reporter1.SpecSummaries
				Ω(summaries).Should(HaveLen(6))
				Ω(summaries[0].ComponentTexts).Should(ContainElement("spec A"))
				Ω(summaries[0].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[1].ComponentTexts).Should(ContainElement("pending spec"))
				Ω(summaries[1].State).Should(Equal(types.SpecStatePending))
				Ω(summaries[2].ComponentTexts).Should(ContainElement("flaky spec"))
				Ω(summaries[2].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[3].ComponentTexts).Should(ContainElement("failed spec"))
				Ω(summaries[3].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[4].ComponentTexts).Should(ContainElement("spec B"))
				Ω(summaries[4].State).Should(Equal(types.SpecStatePassed))
				Ω(summaries[5].ComponentTexts).Should(ContainElement("skipped spec"))
				Ω(summaries[5].State).Should(Equal(types.SpecStateSkipped))
			})

			It("should report the end of the suite", func() {
				Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
				Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
				Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
				Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
				Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(4))
				Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(1))
				Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
				Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(0))
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
			})
		})
	})

	Describe("Running BeforeSuite & AfterSuite", func() {
		var success bool
		var befSuite leafnodes.SuiteNode
		var aftSuite leafnodes.SuiteNode
		Context("with a nil BeforeSuite & AfterSuite", func() {
			BeforeEach(func() {
				runner = newRunner(
					config.GinkgoConfigType{},
					nil,
					nil,
					newSpec("A", noneFlag, false),
					newSpec("B", noneFlag, false),
				)
				success = runner.Run()
			})

			It("should not report about the BeforeSuite", func() {
				Ω(reporter1.BeforeSuiteSummary).Should(BeNil())
			})

			It("should not report about the AfterSuite", func() {
				Ω(reporter1.AfterSuiteSummary).Should(BeNil())
			})

			It("should run the specs", func() {
				Ω(thingsThatRan).Should(Equal([]string{"A", "B"}))
			})
		})

		Context("when the BeforeSuite & AfterSuite pass", func() {
			BeforeEach(func() {
				befSuite = newBefSuite("BefSuite", false)
				aftSuite = newBefSuite("AftSuite", false)
				runner = newRunner(
					config.GinkgoConfigType{},
					befSuite,
					aftSuite,
					newSpec("A", noneFlag, false),
					newSpec("B", noneFlag, false),
				)
				success = runner.Run()
			})

			It("should run the BeforeSuite, the AfterSuite and the specs", func() {
				Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "A", "B", "AftSuite"}))
			})

			It("should report about the BeforeSuite", func() {
				Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
			})

			It("should report about the AfterSuite", func() {
				Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
			})

			It("should report success", func() {
				Ω(success).Should(BeTrue())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
			})

			It("should not dump the writer", func() {
				Ω(writer.EventStream).ShouldNot(ContainElement("DUMP"))
			})
		})

		Context("when the BeforeSuite fails", func() {
			BeforeEach(func() {
				befSuite = newBefSuite("BefSuite", true)
				aftSuite = newBefSuite("AftSuite", false)

				skipped := newSpec("Skipped", noneFlag, false)
				skipped.Skip()

				runner = newRunner(
					config.GinkgoConfigType{},
					befSuite,
					aftSuite,
					newSpec("A", noneFlag, false),
					newSpec("B", noneFlag, false),
					newSpec("Pending", pendingFlag, false),
					skipped,
				)
				success = runner.Run()
			})

			It("should not run the specs, but it should run the AfterSuite", func() {
				Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "AftSuite"}))
			})

			It("should report about the BeforeSuite", func() {
				Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
			})

			It("should report about the AfterSuite", func() {
				Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
			})

			It("should report failure", func() {
				Ω(success).Should(BeFalse())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(2))
				Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(2))
			})

			It("should dump the writer", func() {
				Ω(writer.EventStream).Should(ContainElement("DUMP"))
			})
		})

		Context("when some other test fails", func() {
			BeforeEach(func() {
				aftSuite = newBefSuite("AftSuite", false)

				runner = newRunner(
					config.GinkgoConfigType{},
					nil,
					aftSuite,
					newSpec("A", noneFlag, true),
				)
				success = runner.Run()
			})

			It("should still run the AfterSuite", func() {
				Ω(thingsThatRan).Should(Equal([]string{"A", "AftSuite"}))
			})

			It("should report about the AfterSuite", func() {
				Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
			})

			It("should report failure", func() {
				Ω(success).Should(BeFalse())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(1))
				Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(1))
			})
		})

		Context("when the AfterSuite fails", func() {
			BeforeEach(func() {
				befSuite = newBefSuite("BefSuite", false)
				aftSuite = newBefSuite("AftSuite", true)
				runner = newRunner(
					config.GinkgoConfigType{},
					befSuite,
					aftSuite,
					newSpec("A", noneFlag, false),
					newSpec("B", noneFlag, false),
				)
				success = runner.Run()
			})

			It("should run everything", func() {
				Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "A", "B", "AftSuite"}))
			})

			It("should report about the BeforeSuite", func() {
				Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
			})

			It("should report about the AfterSuite", func() {
				Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
			})

			It("should report failure", func() {
				Ω(success).Should(BeFalse())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
				Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
			})

			It("should dump the writer", func() {
				Ω(writer.EventStream).Should(ContainElement("DUMP"))
			})
		})
	})

	Describe("When instructed to fail fast", func() {
		BeforeEach(func() {
			conf := config.GinkgoConfigType{
				FailFast: true,
			}
			runner = newRunner(conf, nil, newAftSuite("after-suite", false), newSpec("passing", noneFlag, false), newSpec("failing", noneFlag, true), newSpec("dont-see", noneFlag, true), newSpec("dont-see", noneFlag, true))
		})

		It("should return false, report failure, and not run anything past the failing test", func() {
			Ω(runner.Run()).Should(BeFalse())
			Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
			Ω(thingsThatRan).Should(Equal([]string{"passing", "failing", "after-suite"}))
		})

		It("should announce the subsequent specs as skipped", func() {
			runner.Run()
			Ω(reporter1.SpecSummaries).Should(HaveLen(4))
			Ω(reporter1.SpecSummaries[2].State).Should(Equal(types.SpecStateSkipped))
			Ω(reporter1.SpecSummaries[3].State).Should(Equal(types.SpecStateSkipped))
		})

		It("should mark all subsequent specs as skipped", func() {
			runner.Run()
			Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(2))
		})
	})

	Describe("Marking failure and success", func() {
		Context("when all tests pass", func() {
			BeforeEach(func() {
				runner = newRunner(config.GinkgoConfigType{}, nil, nil, newSpec("passing", noneFlag, false), newSpec("pending", pendingFlag, false))
			})

			It("should return true and report success", func() {
				Ω(runner.Run()).Should(BeTrue())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
			})
		})

		Context("when a test fails", func() {
			BeforeEach(func() {
				runner = newRunner(config.GinkgoConfigType{}, nil, nil, newSpec("failing", noneFlag, true), newSpec("pending", pendingFlag, false))
			})

			It("should return false and report failure", func() {
				Ω(runner.Run()).Should(BeFalse())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
			})
		})

		Context("when there is a pending test, but pendings count as failures", func() {
			BeforeEach(func() {
				runner = newRunner(config.GinkgoConfigType{FailOnPending: true}, nil, nil, newSpec("passing", noneFlag, false), newSpec("pending", pendingFlag, false))
			})

			It("should return false and report failure", func() {
				Ω(runner.Run()).Should(BeFalse())
				Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
			})
		})
	})

	Describe("Managing the writer", func() {
		BeforeEach(func() {
			runner = newRunner(
				config.GinkgoConfigType{},
				nil,
				nil,
				newSpec("A", noneFlag, false),
				newSpec("B", noneFlag, true),
				newSpec("C", noneFlag, false),
			)
			reporter1.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				writer.AddEvent("R1.WillRun")
			}
			reporter2.SpecWillRunStub = func(specSummary *types.SpecSummary) {
				writer.AddEvent("R2.WillRun")
			}
			reporter1.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				writer.AddEvent("R1.DidComplete")
			}
			reporter2.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
				writer.AddEvent("R2.DidComplete")
			}
			runner.Run()
		})

		It("should truncate between tests, but only dump if a test fails", func() {
			Ω(writer.EventStream).Should(Equal([]string{
				"TRUNCATE",
				"R1.WillRun",
				"R2.WillRun",
				"A",
				"R2.DidComplete",
				"R1.DidComplete",
				"TRUNCATE",
				"R1.WillRun",
				"R2.WillRun",
				"B",
				"BYTES",
				"R2.DidComplete",
				"DUMP",
				"R1.DidComplete",
				"TRUNCATE",
				"R1.WillRun",
				"R2.WillRun",
				"C",
				"R2.DidComplete",
				"R1.DidComplete",
			}))
		})
	})

	Describe("CurrentSpecSummary", func() {
		It("should return the spec summary for the currently running spec", func() {
			var summary *types.SpecSummary
			runner = newRunner(
				config.GinkgoConfigType{},
				nil,
				nil,
				newSpec("A", noneFlag, false),
				newSpecWithBody("B", func() {
					var ok bool
					summary, ok = runner.CurrentSpecSummary()
					Ω(ok).Should(BeTrue())
				}),
				newSpec("C", noneFlag, false),
			)
			runner.Run()

			Ω(summary.ComponentTexts).Should(Equal([]string{"B"}))

			summary, ok := runner.CurrentSpecSummary()
			Ω(summary).Should(BeNil())
			Ω(ok).Should(BeFalse())
		})
	})

	Describe("generating a suite id", func() {
		It("should generate an id randomly", func() {
			runnerA := newRunner(config.GinkgoConfigType{}, nil, nil)
			runnerA.Run()
			IDA := reporter1.BeginSummary.SuiteID

			runnerB := newRunner(config.GinkgoConfigType{}, nil, nil)
			runnerB.Run()
			IDB := reporter1.BeginSummary.SuiteID

			IDRegexp := "[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"
			Ω(IDA).Should(MatchRegexp(IDRegexp))
			Ω(IDB).Should(MatchRegexp(IDRegexp))

			Ω(IDA).ShouldNot(Equal(IDB))
		})
	})
})