...
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("BeFalse and BeFalseBecause", func() {
10 It("should handle true and false correctly", func() {
11 Expect(true).ShouldNot(BeFalse())
12 Expect(false).Should(BeFalse())
13 })
14
15 It("should only support booleans", func() {
16 success, err := (&BeFalseMatcher{}).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 := 100
23 err := InterceptGomegaFailure(func() { Expect(x == 100).Should(BeFalse()) })
24 Ω(err.Error()).Should(Equal("Expected\n <bool>: true\nto be false"))
25
26 err = InterceptGomegaFailure(func() { Expect(x == 100).Should(BeFalseBecause("x should not be 100%%")) })
27 Ω(err.Error()).Should(Equal("x should not be 100%"))
28
29 err = InterceptGomegaFailure(func() { Expect(x == 100).Should(BeFalseBecause("x should not be %d%%", 100)) })
30 Ω(err.Error()).Should(Equal("x should not be 100%"))
31 })
32
33 It("prints out a useful message if a negation fails", func() {
34 x := 10
35 err := InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeFalse()) })
36 Ω(err.Error()).Should(Equal("Expected\n <bool>: false\nnot to be false"))
37
38 err = InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeFalseBecause("x should not be 100%%")) })
39 Ω(err.Error()).Should(Equal(`Expected not false but got false\nNegation of "x should not be 100%" failed`))
40
41 err = InterceptGomegaFailure(func() { Expect(x == 100).ShouldNot(BeFalseBecause("x should not be %d%%", 100)) })
42 Ω(err.Error()).Should(Equal(`Expected not false but got false\nNegation of "x should not be 100%" failed`))
43 })
44 })
45
View as plain text