/
subcommand_test.go
665 lines (525 loc) · 24.3 KB
/
subcommand_test.go
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
package integration_test
import (
"os"
"strings"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/types"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("Subcommand", func() {
Describe("ginkgo bootstrap", func() {
var pkg string
BeforeEach(func() {
pkg = "foo"
fm.MkEmpty(pkg)
})
It("should generate a bootstrap file, as long as one does not exist", func() {
session := startGinkgo(fm.PathTo(pkg), "bootstrap")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
content := fm.ContentOf(pkg, "foo_suite_test.go")
Ω(content).Should(ContainSubstring("package foo_test"))
Ω(content).Should(ContainSubstring("func TestFoo(t *testing.T) {"))
Ω(content).Should(ContainSubstring("RegisterFailHandler"))
Ω(content).Should(ContainSubstring("RunSpecs"))
Ω(content).Should(ContainSubstring("\t" + `. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring("\t" + `. "github.com/onsi/gomega"`))
session = startGinkgo(fm.PathTo(pkg))
Eventually(session).Should(gexec.Exit(0))
session = startGinkgo(fm.PathTo(pkg), "bootstrap")
Eventually(session).Should(gexec.Exit(1))
output = session.Err.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
Ω(output).Should(ContainSubstring("already exists"))
})
It("should generate a bootstrap file with a working package name if the folder starts with a numeral", func() {
fm.MkEmpty("7")
session := startGinkgo(fm.PathTo("7"), "bootstrap")
Eventually(session).Should(gexec.Exit(0))
content := fm.ContentOf("7", "7_suite_test.go")
pkg := strings.Split(content, "\n")[0]
Ω(pkg).Should(Equal("package seven_test"))
session = startGinkgo(fm.PathTo("7"))
Eventually(session).Should(gexec.Exit(0))
})
It("should import nodot declarations when told to", func() {
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--nodot")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
content := fm.ContentOf(pkg, "foo_suite_test.go")
Ω(content).Should(ContainSubstring("package foo_test"))
Ω(content).Should(ContainSubstring("func TestFoo(t *testing.T) {"))
Ω(content).Should(ContainSubstring("gomega.RegisterFailHandler"))
Ω(content).Should(ContainSubstring("ginkgo.RunSpecs"))
Ω(content).Should(ContainSubstring("\t" + `"github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring("\t" + `"github.com/onsi/gomega"`))
session = startGinkgo(fm.PathTo(pkg))
Eventually(session).Should(gexec.Exit(0))
})
It("should generate a bootstrap file using a template when told to", func() {
fm.WriteFile(pkg, ".bootstrap", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
"testing"
"binary"
)
func Test{{.FormattedName}}(t *testing.T) {
// This is a {{.Package}} test
}`)
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--template", ".bootstrap")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
content := fm.ContentOf(pkg, "foo_suite_test.go")
Ω(content).Should(ContainSubstring("package foo_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`"binary"`))
Ω(content).Should(ContainSubstring("// This is a foo_test test"))
})
It("should generate a bootstrap file using a template that contains functions when told to", func() {
fm.WriteFile(pkg, ".bootstrap", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
"testing"
"binary"
)
func Test{{.FormattedName}}(t *testing.T) {
// This is a {{.Package | repeat 3}} test
}`)
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--template", ".bootstrap")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
content := fm.ContentOf(pkg, "foo_suite_test.go")
Ω(content).Should(ContainSubstring("package foo_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`"binary"`))
Ω(content).Should(ContainSubstring("// This is a foo_testfoo_testfoo_test test"))
})
It("should generate a bootstrap file using a template and custom template data when told to", func() {
fm.WriteFile(pkg, ".bootstrap", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
"testing"
"binary"
)
func Test{{.FormattedName}}(t *testing.T) {
// This is a {{.Package | repeat 3}} test
// This is a custom data {{.CustomData.suitename}} test
}`)
fm.WriteFile(pkg, "custom.json", `{"suitename": "integration"}`)
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--template", ".bootstrap", "--template-data", "custom.json")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_suite_test.go"))
content := fm.ContentOf(pkg, "foo_suite_test.go")
Ω(content).Should(ContainSubstring("package foo_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`"binary"`))
Ω(content).Should(ContainSubstring("// This is a foo_testfoo_testfoo_test test"))
Ω(content).Should(ContainSubstring("// This is a custom data integration test"))
})
It("should fail to render a bootstrap file using a template and custom template data when accessing a missing key", func() {
fm.WriteFile(pkg, ".bootstrap", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
"testing"
"binary"
)
func Test{{.FormattedName}}(t *testing.T) {
// This is a {{.Package | repeat 3}} test
// This is a custom data {{.CustomData.component}} test
}`)
fm.WriteFile(pkg, "custom.json", `{"suitename": "integration"}`)
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--template", ".bootstrap", "--template-data", "custom.json")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Err.Contents())
Ω(output).Should(ContainSubstring(`executing "bootstrap" at <.CustomData.component>: map has no entry for key "component"`))
})
It("should fail to render a bootstrap file using a template and custom template data when data is invalid JSON", func() {
fm.WriteFile(pkg, ".bootstrap", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
"testing"
"binary"
)
func Test{{.FormattedName}}(t *testing.T) {
// This is a {{.Package | repeat 3}} test
// This is a custom data {{.CustomData.component}} test
}`)
fm.WriteFile(pkg, "custom.json", `{'suitename': 'integration']`)
session := startGinkgo(fm.PathTo(pkg), "bootstrap", "--template", ".bootstrap", "--template-data", "custom.json")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Err.Contents())
Ω(output).Should(ContainSubstring(`Invalid JSON object in custom data file.`))
})
})
Describe("ginkgo generate", func() {
var pkg string
BeforeEach(func() {
pkg = "foo_bar"
fm.MkEmpty(pkg)
Eventually(startGinkgo(fm.PathTo(pkg), "bootstrap")).Should(gexec.Exit(0))
})
Context("with no arguments", func() {
It("should generate a test file named after the package", func() {
session := startGinkgo(fm.PathTo(pkg), "generate")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
By("having the correct content")
content := fm.ContentOf(pkg, "foo_bar_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("FooBar", func() {`))
Ω(content).Should(ContainSubstring("\t" + `. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring("\t" + `. "github.com/onsi/gomega"`))
By("compiling correctly (we append to the file to make sure gomega is used)")
fm.WriteFile(pkg, "foo_bar.go", "package foo_bar\nvar TRUE=true\n")
fm.AppendToFile(pkg, "foo_bar_test.go", strings.Join([]string{``,
`var _ = It("works", func() {`,
` Expect(foo_bar.TRUE).To(BeTrue())`,
`})`,
}, "\n"))
Eventually(startGinkgo(fm.PathTo(pkg))).Should(gexec.Exit(0))
By("refusing to overwrite the file if generate is called again")
session = startGinkgo(fm.PathTo(pkg), "generate")
Eventually(session).Should(gexec.Exit(1))
output = session.Err.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
Ω(output).Should(ContainSubstring("already exists"))
})
})
Context("with template argument", func() {
It("should generate a test file using a template", func() {
fm.WriteFile(pkg, ".generate", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
)
var _ = Describe("{{.Subject}}", func() {
// This is a {{.Package}} test
})`)
session := startGinkgo(fm.PathTo(pkg), "generate", "--template", ".generate")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
content := fm.ContentOf(pkg, "foo_bar_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`/foo_bar"`))
Ω(content).Should(ContainSubstring("// This is a foo_bar_test test"))
})
It("should generate a test file using a template that contains functions", func() {
fm.WriteFile(pkg, ".generate", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
)
var _ = Describe("{{.Subject}}", func() {
// This is a {{.Package | repeat 3 }} test
})`)
session := startGinkgo(fm.PathTo(pkg), "generate", "--template", ".generate")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
content := fm.ContentOf(pkg, "foo_bar_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`/foo_bar"`))
Ω(content).Should(ContainSubstring("// This is a foo_bar_testfoo_bar_testfoo_bar_test test"))
})
It("should generate a test file using a template and custom data when told to", func() {
fm.WriteFile(pkg, ".generate", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
)
var _ = Describe("{{.Subject}}", Label("{{.CustomData.label}}"), func() {
// This is a {{.Package | repeat 3 }} test
})`)
fm.WriteFile(pkg, "custom_spec.json", `{"label": "integration"}`)
session := startGinkgo(fm.PathTo(pkg), "generate", "--template", ".generate", "--template-data", "custom_spec.json")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
content := fm.ContentOf(pkg, "foo_bar_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring(`. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring(`/foo_bar"`))
Ω(content).Should(ContainSubstring("// This is a foo_bar_testfoo_bar_testfoo_bar_test test"))
Ω(content).Should(ContainSubstring(`Label("integration")`))
})
It("should fail to render a test file using a template and custom template data when accessing a missing key", func() {
fm.WriteFile(pkg, ".generate", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
)
var _ = Describe("{{.Subject}}", Label("{{.CustomData.component}}"), func() {
// This is a {{.Package | repeat 3 }} test
})`)
fm.WriteFile(pkg, "custom.json", `{"label": "integration"}`)
session := startGinkgo(fm.PathTo(pkg), "generate", "--template", ".generate", "--template-data", "custom.json")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Err.Contents())
Ω(output).Should(ContainSubstring(`executing "spec" at <.CustomData.component>: map has no entry for key "component"`))
})
It("should fail to render a test file using a template and custom template data when data is invalid JSON", func() {
fm.WriteFile(pkg, ".generate", `package {{.Package}}
import (
{{.GinkgoImport}}
{{.GomegaImport}}
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
)
var _ = Describe("{{.Subject}}", Label("{{.CustomData.label}}"), func() {
// This is a {{.Package | repeat 3 }} test
})`)
fm.WriteFile(pkg, "custom.json", `{'label': 'integration']`)
session := startGinkgo(fm.PathTo(pkg), "generate", "--template", ".generate", "--template-data", "custom.json")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Err.Contents())
Ω(output).Should(ContainSubstring(`Invalid JSON object in custom data file.`))
})
})
Context("with an argument of the form: foo", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz_buzz")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_buzz_test.go"))
content := fm.ContentOf(pkg, "baz_buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})
Context("with an argument of the form: foo.go", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz_buzz.go")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_buzz_test.go"))
content := fm.ContentOf(pkg, "baz_buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})
Context("with an argument of the form: foo_test", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz_buzz_test")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_buzz_test.go"))
content := fm.ContentOf(pkg, "baz_buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})
Context("with an argument of the form: foo-test", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz-buzz-test")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_buzz_test.go"))
content := fm.ContentOf(pkg, "baz_buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})
Context("with an argument of the form: foo_test.go", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz_buzz_test.go")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_buzz_test.go"))
content := fm.ContentOf(pkg, "baz_buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})
Context("with multiple arguments", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "baz", "buzz")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("baz_test.go"))
Ω(output).Should(ContainSubstring("buzz_test.go"))
content := fm.ContentOf(pkg, "baz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("Baz", func() {`))
content = fm.ContentOf(pkg, "buzz_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("Buzz", func() {`))
})
})
Context("with nodot", func() {
It("should not import ginkgo or gomega", func() {
session := startGinkgo(fm.PathTo(pkg), "generate", "--nodot")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(ContainSubstring("foo_bar_test.go"))
content := fm.ContentOf(pkg, "foo_bar_test.go")
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).ShouldNot(ContainSubstring("\t" + `. "github.com/onsi/ginkgo/v2"`))
Ω(content).ShouldNot(ContainSubstring("\t" + `. "github.com/onsi/gomega"`))
Ω(content).Should(ContainSubstring("\t" + `"github.com/onsi/ginkgo/v2"`))
Ω(content).Should(ContainSubstring("\t" + `"github.com/onsi/gomega"`))
By("compiling correctly (we append to the file to make sure gomega is used)")
fm.WriteFile(pkg, "foo_bar.go", "package foo_bar\nvar TRUE=true\n")
fm.AppendToFile(pkg, "foo_bar_test.go", strings.Join([]string{``,
`var _ = ginkgo.It("works", func() {`,
` gomega.Expect(foo_bar.TRUE).To(gomega.BeTrue())`,
`})`,
}, "\n"))
Eventually(startGinkgo(fm.PathTo(pkg))).Should(gexec.Exit(0))
})
})
})
Describe("ginkgo bootstrap/generate", func() {
var pkg string
BeforeEach(func() {
pkg = "some-crazy-thing"
fm.MkEmpty(pkg)
})
Context("when the working directory is empty", func() {
It("generates correctly named bootstrap and generate files with a package name derived from the directory", func() {
session := startGinkgo(fm.PathTo(pkg), "bootstrap")
Eventually(session).Should(gexec.Exit(0))
content := fm.ContentOf(pkg, "some_crazy_thing_suite_test.go")
Ω(content).Should(ContainSubstring("package some_crazy_thing_test"))
Ω(content).Should(ContainSubstring("SomeCrazyThing Suite"))
session = startGinkgo(fm.PathTo(pkg), "generate")
Eventually(session).Should(gexec.Exit(0))
content = fm.ContentOf(pkg, "some_crazy_thing_test.go")
Ω(content).Should(ContainSubstring("package some_crazy_thing_test"))
Ω(content).Should(ContainSubstring("SomeCrazyThing"))
})
})
Context("when the working directory contains a file with a package name", func() {
BeforeEach(func() {
fm.WriteFile(pkg, "foo.go", "package main\n\nfunc main() {}")
})
It("generates correctly named bootstrap and generate files with the package name", func() {
session := startGinkgo(fm.PathTo(pkg), "bootstrap")
Eventually(session).Should(gexec.Exit(0))
content := fm.ContentOf(pkg, "some_crazy_thing_suite_test.go")
Ω(content).Should(ContainSubstring("package main_test"))
Ω(content).Should(ContainSubstring("SomeCrazyThing Suite"))
session = startGinkgo(fm.PathTo(pkg), "generate")
Eventually(session).Should(gexec.Exit(0))
content = fm.ContentOf(pkg, "some_crazy_thing_test.go")
Ω(content).Should(ContainSubstring("package main_test"))
Ω(content).Should(ContainSubstring("SomeCrazyThing"))
})
})
})
Describe("Go module and ginkgo bootstrap/generate", func() {
var (
pkg string
savedGoPath string
)
BeforeEach(func() {
pkg = "myamazingmodule"
fm.MkEmpty(pkg)
fm.WriteFile(pkg, "go.mod", "module fake.com/me/myamazingmodule\n")
savedGoPath = os.Getenv("GOPATH")
Expect(os.Setenv("GOPATH", "")).To(Succeed())
Expect(os.Setenv("GO111MODULE", "on")).To(Succeed()) // needed pre-Go 1.13
})
AfterEach(func() {
Expect(os.Setenv("GOPATH", savedGoPath)).To(Succeed())
Expect(os.Setenv("GO111MODULE", "")).To(Succeed())
})
It("generates correctly named bootstrap and generate files with the module name", func() {
session := startGinkgo(fm.PathTo(pkg), "bootstrap")
Eventually(session).Should(gexec.Exit(0))
content := fm.ContentOf(pkg, "myamazingmodule_suite_test.go")
Expect(content).To(ContainSubstring("package myamazingmodule_test"), string(content))
Expect(content).To(ContainSubstring("Myamazingmodule Suite"), string(content))
session = startGinkgo(fm.PathTo(pkg), "generate")
Eventually(session).Should(gexec.Exit(0))
content = fm.ContentOf(pkg, "myamazingmodule_test.go")
Expect(content).To(ContainSubstring("package myamazingmodule_test"), string(content))
Expect(content).To(ContainSubstring("fake.com/me/myamazingmodule"), string(content))
Expect(content).To(ContainSubstring("Myamazingmodule"), string(content))
})
})
Describe("ginkgo unfocus", func() {
It("should unfocus tests", Label("slow"), func() {
fm.MountFixture("focused")
session := startGinkgo(fm.PathTo("focused"), "--no-color", "-r")
Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE))
output := session.Out.Contents()
Ω(string(output)).Should(ContainSubstring("Detected Programmatic Focus"))
session = startGinkgo(fm.PathTo("focused"), "unfocus")
Eventually(session).Should(gexec.Exit(0))
output = session.Out.Contents()
Ω(string(output)).ShouldNot(ContainSubstring("expected 'package'"))
session = startGinkgo(fm.PathTo("focused"), "--no-color", "-r")
Eventually(session).Should(gexec.Exit(0))
output = session.Out.Contents()
Ω(string(output)).Should(ContainSubstring("Ginkgo ran 2 suites"))
Ω(string(output)).Should(ContainSubstring("Test Suite Passed"))
Ω(string(output)).ShouldNot(ContainSubstring("Detected Programmatic Focus"))
original := fm.ContentOfFixture("focused", "README.md")
updated := fm.ContentOf("focused", "README.md")
Ω(original).Should(Equal(updated))
})
It("should ignore the 'vendor' folder", func() {
fm.MountFixture("focused_with_vendor")
session := startGinkgo(fm.PathTo("focused_with_vendor"), "unfocus")
Eventually(session).Should(gexec.Exit(0))
session = startGinkgo(fm.PathTo("focused_with_vendor"), "--no-color")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Expect(string(output)).To(ContainSubstring("11 Passed"))
Expect(string(output)).To(ContainSubstring("0 Skipped"))
originalVendorPath := fm.PathToFixtureFile("focused_with_vendor", "vendor")
updatedVendorPath := fm.PathTo("focused_with_vendor", "vendor")
Expect(sameFolder(originalVendorPath, updatedVendorPath)).To(BeTrue())
})
})
Describe("ginkgo version", func() {
It("should print out the version info", func() {
session := startGinkgo("", "version")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()
Ω(output).Should(MatchRegexp(`Ginkgo Version \d+\.\d+\.\d+`))
})
})
Describe("ginkgo help", func() {
It("should print out usage information", func() {
session := startGinkgo("", "help")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(output).Should(MatchRegexp(`Ginkgo Version \d+\.\d+\.\d+`))
Ω(output).Should(ContainSubstring("watch"))
Ω(output).Should(ContainSubstring("generate"))
Ω(output).Should(ContainSubstring("run"))
})
It("should print out usage information for subcommands", func() {
session := startGinkgo("", "help", "run")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("-succinct"))
Ω(output).Should(ContainSubstring("-procs"))
})
})
})