github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/spec_test.go (about) 1 package internal_test 2 3 import ( 4 . "github.com/onsi/ginkgo" 5 "github.com/onsi/ginkgo/internal" 6 . "github.com/onsi/gomega" 7 ) 8 9 var _ = Describe("Spec and Specs", func() { 10 Describe("spec.Text", func() { 11 Context("when the spec has nodes with texts", func() { 12 It("returns the concatenated texts of its nodes (omitting any empty texts)", func() { 13 spec := S(N(), N("Oh death,"), N(), N("where is"), N("thy"), N(), N("sting?")) 14 Ω(spec.Text()).Should(Equal("Oh death, where is thy sting?")) 15 }) 16 }) 17 18 Context("when the spec has no nodes", func() { 19 It("returns the empty string", func() { 20 Ω(Spec{}.Text()).Should(BeZero()) 21 }) 22 }) 23 }) 24 25 Describe("spec.FirstNodeWithType", func() { 26 Context("when there are matching nodes", func() { 27 It("returns the first node matching any of the passed in node types", func() { 28 nBef := N(ntBef) 29 nIt := N(ntIt) 30 spec := S(N(ntCon), N(ntAf), nBef, N(ntBef), nIt, N(ntAf)) 31 Ω(spec.FirstNodeWithType(ntIt | ntBef)).Should(Equal(nBef)) 32 }) 33 }) 34 35 Context("when no nodes match", func() { 36 It("returns zero", func() { 37 spec := S(N(ntCon), N(ntIt), N(ntAf)) 38 Ω(spec.FirstNodeWithType(ntBef)).Should(BeZero()) 39 }) 40 }) 41 }) 42 43 Describe("spec.FlakeAttempts", func() { 44 Context("when none of the nodes have FlakeAttempt", func() { 45 It("returns 0", func() { 46 spec := S(N(ntCon), N(ntCon), N(ntIt)) 47 Ω(spec.FlakeAttempts()).Should(Equal(0)) 48 }) 49 }) 50 51 Context("when a node has FlakeAttempt set", func() { 52 It("returns that FlakeAttempt", func() { 53 spec := S(N(ntCon, FlakeAttempts(3)), N(ntCon), N(ntIt)) 54 Ω(spec.FlakeAttempts()).Should(Equal(3)) 55 56 spec = S(N(ntCon), N(ntCon, FlakeAttempts(2)), N(ntIt)) 57 Ω(spec.FlakeAttempts()).Should(Equal(2)) 58 59 spec = S(N(ntCon), N(ntCon), N(ntIt, FlakeAttempts(4))) 60 Ω(spec.FlakeAttempts()).Should(Equal(4)) 61 }) 62 }) 63 64 Context("when multiple nodes have FlakeAttempt", func() { 65 It("returns the inner-most nested FlakeAttempt", func() { 66 spec := S(N(ntCon, FlakeAttempts(3)), N(ntCon, FlakeAttempts(4)), N(ntIt, FlakeAttempts(2))) 67 Ω(spec.FlakeAttempts()).Should(Equal(2)) 68 }) 69 }) 70 }) 71 72 Describe("specs.HasAnySpecsMarkedPending", func() { 73 Context("when there are no specs with any nodes marked pending", func() { 74 It("returns false", func() { 75 specs := Specs{ 76 S(N(), N(), N()), 77 S(N(), N()), 78 } 79 80 Ω(specs.HasAnySpecsMarkedPending()).Should(BeFalse()) 81 }) 82 }) 83 84 Context("when there is at least one spec with a node marked pending", func() { 85 It("returns true", func() { 86 specs := Specs{ 87 S(N(), N(), N()), 88 S(N(), N(Pending), N()), 89 S(N(), N()), 90 } 91 92 Ω(specs.HasAnySpecsMarkedPending()).Should(BeTrue()) 93 }) 94 }) 95 }) 96 97 Describe("specs.CountWithoutSkip()", func() { 98 It("returns the number of specs that have skip set to false", func() { 99 specs := Specs{{Skip: false}, {Skip: true}, {Skip: true}, {Skip: false}, {Skip: false}} 100 Ω(specs.CountWithoutSkip()).Should(Equal(3)) 101 }) 102 }) 103 104 Describe("specs.AtIndices", func() { 105 It("returns the subset of specs at the specified indices", func() { 106 specs := Specs{S(N()), S(N()), S(N()), S(N())} 107 Ω(specs.AtIndices(internal.SpecIndices{1, 3})).Should(Equal(Specs{specs[1], specs[3]})) 108 }) 109 }) 110 })