github.com/cloudfoundry-attic/ltc@v0.0.0-20151123212628-098adc7919fc/test_helpers/regex_safe_say_test.go (about) 1 package test_helpers_test 2 3 import ( 4 . "github.com/onsi/ginkgo" 5 . "github.com/onsi/gomega" 6 "github.com/onsi/gomega/gbytes" 7 8 "github.com/cloudfoundry-incubator/ltc/test_helpers" 9 ) 10 11 var _ = Describe("RegexSafeSay", func() { 12 var outputBuffer *gbytes.Buffer 13 14 BeforeEach(func() { 15 outputBuffer = gbytes.NewBuffer() 16 }) 17 18 Describe("Say", func() { 19 BeforeEach(func() { 20 outputBuffer.Write([]byte(`match this \|?-^$.(){}`)) 21 }) 22 It("matches with regex-escaped characters", func() { 23 Expect(outputBuffer).To(test_helpers.Say(`match this \|?-^$.(){}`)) 24 }) 25 It("negated match", func() { 26 Expect(outputBuffer).NotTo(test_helpers.Say("match that")) 27 }) 28 Context("when format string is passed with arguments", func() { 29 It("matches with regex-escaped characters", func() { 30 Expect(outputBuffer).To(test_helpers.Say(`match %s \|?-^$.(){}`, "this")) 31 }) 32 }) 33 }) 34 35 Describe("SayLine", func() { 36 BeforeEach(func() { 37 outputBuffer.Write([]byte(`match this \|?-^$.(){}` + "\n")) 38 }) 39 It("matches with regex-escaped characters", func() { 40 Expect(outputBuffer).To(test_helpers.SayLine(`match this \|?-^$.(){}`)) 41 }) 42 It("negated match", func() { 43 Expect(outputBuffer).NotTo(test_helpers.SayLine("match that")) 44 }) 45 Context("when format string is passed with arguments", func() { 46 It("matches with regex-escaped characters", func() { 47 Expect(outputBuffer).To(test_helpers.SayLine(`match %s \|?-^$.(){}`, "this")) 48 }) 49 }) 50 }) 51 52 Describe("SayIncorrectUsage", func() { 53 It("matches", func() { 54 outputBuffer.Write([]byte("Incorrect Usage")) 55 Expect(outputBuffer).To(test_helpers.SayIncorrectUsage()) 56 }) 57 It("negated match", func() { 58 outputBuffer.Write([]byte("say that")) 59 Expect(outputBuffer).NotTo(test_helpers.SayIncorrectUsage()) 60 }) 61 }) 62 63 Describe("SayNewLine", func() { 64 It("matches a newline character", func() { 65 outputBuffer.Write([]byte("\n")) 66 Expect(outputBuffer).To(test_helpers.SayNewLine()) 67 }) 68 It("negated match", func() { 69 outputBuffer.Write([]byte("say that")) 70 Expect(outputBuffer).NotTo(test_helpers.SayNewLine()) 71 }) 72 }) 73 })