4 . "github.com/onsi/gomega/gbytes"
7 . "github.com/onsi/ginkgo"
8 . "github.com/onsi/gomega"
15 func (s *speaker) Buffer() *Buffer {
19 var _ = Describe("SayMatcher", func() {
24 buffer.Write([]byte("abc"))
27 Context("when actual is not a gexec Buffer, or a BufferProvider", func() {
28 It("should error", func() {
29 failures := InterceptGomegaFailures(func() {
30 Ω("foo").Should(Say("foo"))
32 Ω(failures[0]).Should(ContainSubstring("*gbytes.Buffer"))
36 Context("when a match is found", func() {
37 It("should succeed", func() {
38 Ω(buffer).Should(Say("abc"))
41 It("should support printf-like formatting", func() {
42 Ω(buffer).Should(Say("a%sc", "b"))
45 It("should use a regular expression", func() {
46 Ω(buffer).Should(Say("a.c"))
49 It("should fastforward the buffer", func() {
50 buffer.Write([]byte("def"))
51 Ω(buffer).Should(Say("abcd"))
52 Ω(buffer).Should(Say("ef"))
53 Ω(buffer).ShouldNot(Say("[a-z]"))
57 Context("when no match is found", func() {
58 It("should not error", func() {
59 Ω(buffer).ShouldNot(Say("def"))
62 Context("when the buffer is closed", func() {
67 It("should abort an eventually", func() {
69 failures := InterceptGomegaFailures(func() {
70 Eventually(buffer).Should(Say("def"))
72 Eventually(buffer).ShouldNot(Say("def"))
73 Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
74 Ω(failures).Should(HaveLen(1))
77 Eventually(buffer).Should(Say("abc"))
78 Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
81 It("should abort a consistently", func() {
83 Consistently(buffer, 2.0).ShouldNot(Say("def"))
84 Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))
87 It("should not error with a synchronous matcher", func() {
88 Ω(buffer).ShouldNot(Say("def"))
89 Ω(buffer).Should(Say("abc"))
94 Context("when a positive match fails", func() {
95 It("should report where it got stuck", func() {
96 Ω(buffer).Should(Say("abc"))
97 buffer.Write([]byte("def"))
98 failures := InterceptGomegaFailures(func() {
99 Ω(buffer).Should(Say("abc"))
101 Ω(failures[0]).Should(ContainSubstring("Got stuck at:"))
102 Ω(failures[0]).Should(ContainSubstring("def"))
106 Context("when a negative match fails", func() {
107 It("should report where it got stuck", func() {
108 failures := InterceptGomegaFailures(func() {
109 Ω(buffer).ShouldNot(Say("abc"))
111 Ω(failures[0]).Should(ContainSubstring("Saw:"))
112 Ω(failures[0]).Should(ContainSubstring("Which matches the unexpected:"))
113 Ω(failures[0]).Should(ContainSubstring("abc"))
117 Context("when a match is not found", func() {
118 It("should not fastforward the buffer", func() {
119 Ω(buffer).ShouldNot(Say("def"))
120 Ω(buffer).Should(Say("abc"))
124 Context("a nice real-life example", func() {
125 It("should behave well", func() {
126 Ω(buffer).Should(Say("abc"))
128 time.Sleep(10 * time.Millisecond)
129 buffer.Write([]byte("def"))
131 Ω(buffer).ShouldNot(Say("def"))
132 Eventually(buffer).Should(Say("def"))
136 Context("when actual is a BufferProvider", func() {
137 It("should use actual's buffer", func() {
142 Ω(s).ShouldNot(Say("abc"))
144 s.Buffer().Write([]byte("abc"))
145 Ω(s).Should(Say("abc"))
148 It("should abort an eventually", func() {
156 failures := InterceptGomegaFailures(func() {
157 Eventually(s).Should(Say("def"))
159 Ω(failures).Should(HaveLen(1))
160 Ω(time.Since(t)).Should(BeNumerically("<", 500*time.Millisecond))