explain why gomega refuses to compare <nil> to <nil>
diff --git a/matchers/assignable_to_type_of_matcher.go b/matchers/assignable_to_type_of_matcher.go
index 7f8897b..89a1fc2 100644
--- a/matchers/assignable_to_type_of_matcher.go
+++ b/matchers/assignable_to_type_of_matcher.go
@@ -2,8 +2,9 @@
import (
"fmt"
- "github.com/onsi/gomega/format"
"reflect"
+
+ "github.com/onsi/gomega/format"
)
type AssignableToTypeOfMatcher struct {
@@ -12,7 +13,7 @@
func (matcher *AssignableToTypeOfMatcher) Match(actual interface{}) (success bool, err error) {
if actual == nil || matcher.Expected == nil {
- return false, fmt.Errorf("Refusing to compare <nil> to <nil>.")
+ return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
}
actualType := reflect.TypeOf(actual)
diff --git a/matchers/equal_matcher.go b/matchers/equal_matcher.go
index 9f8f80a..d186597 100644
--- a/matchers/equal_matcher.go
+++ b/matchers/equal_matcher.go
@@ -2,8 +2,9 @@
import (
"fmt"
- "github.com/onsi/gomega/format"
"reflect"
+
+ "github.com/onsi/gomega/format"
)
type EqualMatcher struct {
@@ -12,7 +13,7 @@
func (matcher *EqualMatcher) Match(actual interface{}) (success bool, err error) {
if actual == nil && matcher.Expected == nil {
- return false, fmt.Errorf("Refusing to compare <nil> to <nil>.")
+ return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.")
}
return reflect.DeepEqual(actual, matcher.Expected), nil
}