1package reporters_test 2 3import ( 4 "time" 5 6 . "github.com/onsi/ginkgo" 7 "github.com/onsi/ginkgo/config" 8 "github.com/onsi/ginkgo/reporters" 9 st "github.com/onsi/ginkgo/reporters/stenographer" 10 "github.com/onsi/ginkgo/types" 11 . "github.com/onsi/gomega" 12) 13 14var _ = Describe("DefaultReporter", func() { 15 var ( 16 reporter *reporters.DefaultReporter 17 reporterConfig config.DefaultReporterConfigType 18 stenographer *st.FakeStenographer 19 20 ginkgoConfig config.GinkgoConfigType 21 suite *types.SuiteSummary 22 spec *types.SpecSummary 23 ) 24 25 BeforeEach(func() { 26 stenographer = st.NewFakeStenographer() 27 reporterConfig = config.DefaultReporterConfigType{ 28 NoColor: false, 29 SlowSpecThreshold: 0.1, 30 NoisyPendings: false, 31 NoisySkippings: false, 32 Verbose: true, 33 FullTrace: true, 34 } 35 36 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 37 }) 38 39 call := st.NewFakeStenographerCall 40 41 Describe("SpecSuiteWillBegin", func() { 42 BeforeEach(func() { 43 suite = &types.SuiteSummary{ 44 SuiteDescription: "A Sweet Suite", 45 NumberOfTotalSpecs: 10, 46 NumberOfSpecsThatWillBeRun: 8, 47 } 48 49 ginkgoConfig = config.GinkgoConfigType{ 50 RandomSeed: 1138, 51 RandomizeAllSpecs: true, 52 } 53 }) 54 55 Context("when a serial (non-parallel) suite begins", func() { 56 BeforeEach(func() { 57 ginkgoConfig.ParallelTotal = 1 58 59 reporter.SpecSuiteWillBegin(ginkgoConfig, suite) 60 }) 61 62 It("should announce the suite, then announce the number of specs", func() { 63 Ω(stenographer.Calls()).Should(HaveLen(2)) 64 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) 65 Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceNumberOfSpecs", 8, 10, false))) 66 }) 67 }) 68 69 Context("when a parallel suite begins", func() { 70 BeforeEach(func() { 71 ginkgoConfig.ParallelTotal = 2 72 ginkgoConfig.ParallelNode = 1 73 suite.NumberOfSpecsBeforeParallelization = 20 74 75 reporter.SpecSuiteWillBegin(ginkgoConfig, suite) 76 }) 77 78 It("should announce the suite, announce that it's a parallel run, then announce the number of specs", func() { 79 Ω(stenographer.Calls()).Should(HaveLen(2)) 80 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuite", "A Sweet Suite", ginkgoConfig.RandomSeed, true, false))) 81 Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceParallelRun", 1, 2, false))) 82 }) 83 }) 84 }) 85 86 Describe("BeforeSuiteDidRun", func() { 87 Context("when the BeforeSuite passes", func() { 88 It("should announce nothing", func() { 89 reporter.BeforeSuiteDidRun(&types.SetupSummary{ 90 State: types.SpecStatePassed, 91 }) 92 93 Ω(stenographer.Calls()).Should(BeEmpty()) 94 }) 95 }) 96 97 Context("when the BeforeSuite fails", func() { 98 It("should announce the failure", func() { 99 summary := &types.SetupSummary{ 100 State: types.SpecStateFailed, 101 } 102 reporter.BeforeSuiteDidRun(summary) 103 104 Ω(stenographer.Calls()).Should(HaveLen(1)) 105 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceBeforeSuiteFailure", summary, false, true))) 106 }) 107 }) 108 }) 109 110 Describe("AfterSuiteDidRun", func() { 111 Context("when the AfterSuite passes", func() { 112 It("should announce nothing", func() { 113 reporter.AfterSuiteDidRun(&types.SetupSummary{ 114 State: types.SpecStatePassed, 115 }) 116 117 Ω(stenographer.Calls()).Should(BeEmpty()) 118 }) 119 }) 120 121 Context("when the AfterSuite fails", func() { 122 It("should announce the failure", func() { 123 summary := &types.SetupSummary{ 124 State: types.SpecStateFailed, 125 } 126 reporter.AfterSuiteDidRun(summary) 127 128 Ω(stenographer.Calls()).Should(HaveLen(1)) 129 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceAfterSuiteFailure", summary, false, true))) 130 }) 131 }) 132 }) 133 134 Describe("SpecWillRun", func() { 135 Context("When running in verbose mode", func() { 136 Context("and the spec will run", func() { 137 BeforeEach(func() { 138 spec = &types.SpecSummary{} 139 reporter.SpecWillRun(spec) 140 }) 141 142 It("should announce that the spec will run", func() { 143 Ω(stenographer.Calls()).Should(HaveLen(1)) 144 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecWillRun", spec))) 145 }) 146 }) 147 148 Context("and the spec will not run", func() { 149 Context("because it is pending", func() { 150 BeforeEach(func() { 151 spec = &types.SpecSummary{ 152 State: types.SpecStatePending, 153 } 154 reporter.SpecWillRun(spec) 155 }) 156 157 It("should announce nothing", func() { 158 Ω(stenographer.Calls()).Should(BeEmpty()) 159 }) 160 }) 161 162 Context("because it is skipped", func() { 163 BeforeEach(func() { 164 spec = &types.SpecSummary{ 165 State: types.SpecStateSkipped, 166 } 167 reporter.SpecWillRun(spec) 168 }) 169 170 It("should announce nothing", func() { 171 Ω(stenographer.Calls()).Should(BeEmpty()) 172 }) 173 }) 174 }) 175 }) 176 177 Context("When running in verbose & succinct mode", func() { 178 BeforeEach(func() { 179 reporterConfig.Succinct = true 180 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 181 spec = &types.SpecSummary{} 182 reporter.SpecWillRun(spec) 183 }) 184 185 It("should announce nothing", func() { 186 Ω(stenographer.Calls()).Should(BeEmpty()) 187 }) 188 }) 189 190 Context("When not running in verbose mode", func() { 191 BeforeEach(func() { 192 reporterConfig.Verbose = false 193 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 194 spec = &types.SpecSummary{} 195 reporter.SpecWillRun(spec) 196 }) 197 198 It("should announce nothing", func() { 199 Ω(stenographer.Calls()).Should(BeEmpty()) 200 }) 201 }) 202 }) 203 204 Describe("SpecDidComplete", func() { 205 JustBeforeEach(func() { 206 reporter.SpecDidComplete(spec) 207 }) 208 209 BeforeEach(func() { 210 spec = &types.SpecSummary{} 211 }) 212 213 Context("When the spec passed", func() { 214 BeforeEach(func() { 215 spec.State = types.SpecStatePassed 216 }) 217 218 Context("When the spec was a measurement", func() { 219 BeforeEach(func() { 220 spec.IsMeasurement = true 221 }) 222 223 It("should announce the measurement", func() { 224 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, false))) 225 }) 226 }) 227 228 Context("When the spec is slow", func() { 229 BeforeEach(func() { 230 spec.RunTime = time.Second 231 }) 232 233 It("should announce that it was slow", func() { 234 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, false))) 235 }) 236 }) 237 238 Context("When the spec is successful", func() { 239 It("should announce the successful spec", func() { 240 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) 241 }) 242 243 Context("When ReportPassed flag is set", func() { 244 BeforeEach(func() { 245 reporterConfig.ReportPassed = true 246 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 247 spec.CapturedOutput = "test scenario" 248 }) 249 250 It("should announce the captured output", func() { 251 Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceCapturedOutput", spec.CapturedOutput))) 252 }) 253 }) 254 }) 255 }) 256 257 Context("When the spec is pending", func() { 258 BeforeEach(func() { 259 spec.State = types.SpecStatePending 260 }) 261 262 It("should announce the pending spec, succinctly", func() { 263 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnouncePendingSpec", spec, false))) 264 }) 265 }) 266 267 Context("When the spec is skipped", func() { 268 BeforeEach(func() { 269 spec.State = types.SpecStateSkipped 270 }) 271 272 It("should announce the skipped spec, succinctly", func() { 273 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSkippedSpec", spec, true, true))) 274 }) 275 }) 276 277 Context("When the spec timed out", func() { 278 BeforeEach(func() { 279 spec.State = types.SpecStateTimedOut 280 }) 281 282 It("should announce the timedout spec", func() { 283 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, false, true))) 284 }) 285 }) 286 287 Context("When the spec panicked", func() { 288 BeforeEach(func() { 289 spec.State = types.SpecStatePanicked 290 }) 291 292 It("should announce the panicked spec", func() { 293 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecPanicked", spec, false, true))) 294 }) 295 }) 296 297 Context("When the spec failed", func() { 298 BeforeEach(func() { 299 spec.State = types.SpecStateFailed 300 }) 301 302 It("should announce the failed spec", func() { 303 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecFailed", spec, false, true))) 304 }) 305 }) 306 307 Context("in noisy pendings mode", func() { 308 BeforeEach(func() { 309 reporterConfig.Succinct = false 310 reporterConfig.NoisyPendings = true 311 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 312 }) 313 314 Context("When the spec is pending", func() { 315 BeforeEach(func() { 316 spec.State = types.SpecStatePending 317 }) 318 319 It("should announce the pending spec, noisily", func() { 320 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnouncePendingSpec", spec, true))) 321 }) 322 }) 323 }) 324 325 Context("in noisy skippings mode", func() { 326 BeforeEach(func() { 327 reporterConfig.Succinct = false 328 reporterConfig.NoisySkippings = true 329 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 330 }) 331 332 Context("When the spec is skipped", func() { 333 BeforeEach(func() { 334 spec.State = types.SpecStateSkipped 335 }) 336 337 It("should announce the skipped spec, noisily", func() { 338 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSkippedSpec", spec, false, true))) 339 }) 340 }) 341 }) 342 343 Context("in succinct mode", func() { 344 BeforeEach(func() { 345 reporterConfig.Succinct = true 346 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 347 }) 348 349 Context("When the spec passed", func() { 350 BeforeEach(func() { 351 spec.State = types.SpecStatePassed 352 }) 353 354 Context("When the spec was a measurement", func() { 355 BeforeEach(func() { 356 spec.IsMeasurement = true 357 }) 358 359 It("should announce the measurement", func() { 360 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulMeasurement", spec, true))) 361 }) 362 }) 363 364 Context("When the spec is slow", func() { 365 BeforeEach(func() { 366 spec.RunTime = time.Second 367 }) 368 369 It("should announce that it was slow", func() { 370 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSlowSpec", spec, true))) 371 }) 372 }) 373 374 Context("When the spec is successful", func() { 375 It("should announce the successful spec", func() { 376 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSuccesfulSpec", spec))) 377 }) 378 379 Context("When ReportPassed flag is set", func() { 380 BeforeEach(func() { 381 reporterConfig.ReportPassed = true 382 reporter = reporters.NewDefaultReporter(reporterConfig, stenographer) 383 spec.CapturedOutput = "test scenario" 384 }) 385 386 It("should announce the captured output", func() { 387 Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceCapturedOutput", spec.CapturedOutput))) 388 }) 389 }) 390 }) 391 }) 392 393 Context("When the spec is pending", func() { 394 BeforeEach(func() { 395 spec.State = types.SpecStatePending 396 }) 397 398 It("should announce the pending spec, succinctly", func() { 399 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnouncePendingSpec", spec, false))) 400 }) 401 }) 402 403 Context("When the spec is skipped", func() { 404 BeforeEach(func() { 405 spec.State = types.SpecStateSkipped 406 }) 407 408 It("should announce the skipped spec", func() { 409 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSkippedSpec", spec, true, true))) 410 }) 411 }) 412 413 Context("When the spec timed out", func() { 414 BeforeEach(func() { 415 spec.State = types.SpecStateTimedOut 416 }) 417 418 It("should announce the timedout spec", func() { 419 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecTimedOut", spec, true, true))) 420 }) 421 }) 422 423 Context("When the spec panicked", func() { 424 BeforeEach(func() { 425 spec.State = types.SpecStatePanicked 426 }) 427 428 It("should announce the panicked spec", func() { 429 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecPanicked", spec, true, true))) 430 }) 431 }) 432 433 Context("When the spec failed", func() { 434 BeforeEach(func() { 435 spec.State = types.SpecStateFailed 436 }) 437 438 It("should announce the failed spec", func() { 439 Ω(stenographer.Calls()[0]).Should(Equal(call("AnnounceSpecFailed", spec, true, true))) 440 }) 441 }) 442 }) 443 }) 444 445 Describe("SpecSuiteDidEnd", func() { 446 BeforeEach(func() { 447 suite = &types.SuiteSummary{} 448 reporter.SpecSuiteDidEnd(suite) 449 }) 450 451 It("should announce the spec run's completion", func() { 452 Ω(stenographer.Calls()[1]).Should(Equal(call("AnnounceSpecRunCompletion", suite, false))) 453 }) 454 }) 455}) 456