Merge pull request #96 from craigfurman/HaveOccurredMatcher-nil-check-consistency
Can use nil pointers that conform to error interface
diff --git a/matchers/have_occurred_matcher.go b/matchers/have_occurred_matcher.go
index b5095f1..3dfe9e1 100644
--- a/matchers/have_occurred_matcher.go
+++ b/matchers/have_occurred_matcher.go
@@ -9,7 +9,7 @@
}
func (matcher *HaveOccurredMatcher) Match(actual interface{}) (success bool, err error) {
- if actual == nil {
+ if isNil(actual) {
return false, nil
}
diff --git a/matchers/have_occurred_matcher_test.go b/matchers/have_occurred_matcher_test.go
index ef971aa..0fc35a9 100644
--- a/matchers/have_occurred_matcher_test.go
+++ b/matchers/have_occurred_matcher_test.go
@@ -7,6 +7,14 @@
. "github.com/onsi/gomega/matchers"
)
+type CustomErr struct {
+ msg string
+}
+
+func (e *CustomErr) Error() string {
+ return e.msg
+}
+
var _ = Describe("HaveOccurred", func() {
It("should succeed if matching an error", func() {
Ω(errors.New("Foo")).Should(HaveOccurred())
@@ -25,4 +33,14 @@
Ω(success).Should(BeFalse())
Ω(err).Should(HaveOccurred())
})
+
+ It("should succeed with pointer types that conform to error interface", func() {
+ err := &CustomErr{"ohai"}
+ Ω(err).Should(HaveOccurred())
+ })
+
+ It("should not succeed with nil pointers to types that conform to error interface", func() {
+ var err *CustomErr = nil
+ Ω(err).ShouldNot(HaveOccurred())
+ })
})