github.com/onsi/gomega@v1.32.0/matchers/be_true_matcher_test.go (about) 1 package matchers_test 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 . "github.com/onsi/gomega/matchers" 7 ) 8 9 var _ = Describe("BeTrue and BeTrueBecause", func() { 10 It("should handle true and false correctly", func() { 11 Expect(true).Should(BeTrue()) 12 Expect(false).ShouldNot(BeTrue()) 13 }) 14 15 It("should only support booleans", func() { 16 success, err := (&BeTrueMatcher{}).Match("foo") 17 Expect(success).Should(BeFalse()) 18 Expect(err).Should(HaveOccurred()) 19 }) 20 21 It("returns the passed in failure message if provided", func() { 22 x := 10 23 err := InterceptGomegaFailure(func() { Expect(x == 100).Should(BeTrue()) }) 24 Ω(err.Error()).Should(Equal("Expected\n <bool>: false\nto be true")) 25 26 err = InterceptGomegaFailure(func() { Expect(x == 100).Should(BeTrueBecause("x should be 100%%")) }) 27 Ω(err.Error()).Should(Equal("x should be 100%")) 28 29 err = InterceptGomegaFailure(func() { Expect(x == 100).Should(BeTrueBecause("x should be %d%%", 100)) }) 30 Ω(err.Error()).Should(Equal("x should be 100%")) 31 }) 32 33 It("prints out a useful message if a negation fails", func() { 34 x := 100 35 err := InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeTrue()) }) 36 Ω(err.Error()).Should(Equal("Expected\n <bool>: true\nnot to be true")) 37 38 err = InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeTrueBecause("x should be 100%%")) }) 39 Ω(err.Error()).Should(Equal(`Expected not true but got true\nNegation of "x should be 100%" failed`)) 40 41 err = InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeTrueBecause("x should be %d%%", 100)) }) 42 Ω(err.Error()).Should(Equal(`Expected not true but got true\nNegation of "x should be 100%" failed`)) 43 }) 44 })