5 . "github.com/onsi/ginkgo"
6 . "github.com/onsi/gomega"
7 . "github.com/onsi/gomega/matchers"
10 type CustomErr struct {
14 func (e *CustomErr) Error() string {
18 var _ = Describe("HaveOccurred", func() {
19 It("should succeed if matching an error", func() {
20 Ω(errors.New("Foo")).Should(HaveOccurred())
23 It("should not succeed with nil", func() {
24 Ω(nil).ShouldNot(HaveOccurred())
27 It("should only support errors and nil", func() {
28 success, err := (&HaveOccurredMatcher{}).Match("foo")
29 Ω(success).Should(BeFalse())
30 Ω(err).Should(HaveOccurred())
32 success, err = (&HaveOccurredMatcher{}).Match("")
33 Ω(success).Should(BeFalse())
34 Ω(err).Should(HaveOccurred())
37 It("doesn't support non-error type", func() {
38 success, err := (&HaveOccurredMatcher{}).Match(AnyType{})
39 Ω(success).Should(BeFalse())
40 Ω(err).Should(MatchError("Expected an error-type. Got:\n <matchers_test.AnyType>: {}"))
43 It("doesn't support non-error pointer type", func() {
44 success, err := (&HaveOccurredMatcher{}).Match(&AnyType{})
45 Ω(success).Should(BeFalse())
46 Ω(err).Should(MatchError(MatchRegexp(`Expected an error-type. Got:\n <*matchers_test.AnyType | 0x[[:xdigit:]]+>: {}`)))
49 It("should succeed with pointer types that conform to error interface", func() {
50 err := &CustomErr{"ohai"}
51 Ω(err).Should(HaveOccurred())
54 It("should not succeed with nil pointers to types that conform to error interface", func() {
55 var err *CustomErr = nil
56 Ω(err).ShouldNot(HaveOccurred())