...
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("ContainSubstringMatcher", func() {
10 When("actual is a string", func() {
11 It("should match against the string", func() {
12 Expect("Marvelous").Should(ContainSubstring("rve"))
13 Expect("Marvelous").ShouldNot(ContainSubstring("boo"))
14 })
15 })
16
17 When("the matcher is called with multiple arguments", func() {
18 It("should pass the string and arguments to sprintf", func() {
19 Expect("Marvelous3").Should(ContainSubstring("velous%d", 3))
20 })
21 })
22
23 When("actual is a stringer", func() {
24 It("should call the stringer and match agains the returned string", func() {
25 Expect(&myStringer{a: "Abc3"}).Should(ContainSubstring("bc3"))
26 })
27 })
28
29 When("actual is neither a string nor a stringer", func() {
30 It("should error", func() {
31 success, err := (&ContainSubstringMatcher{Substr: "2"}).Match(2)
32 Expect(success).Should(BeFalse())
33 Expect(err).Should(HaveOccurred())
34 })
35 })
36 })
37
View as plain text