diff --git a/CHANGELOG.md b/CHANGELOG.md index fb9c608..174142b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Fix usage of `be ===` and `be =~` [#34](https://github.com/icy-arctic-fox/spectator/issues/34) +- Better handling of the `be(nil)` when used with value types. [#37](https://github.com/icy-arctic-fox/spectator/issues/37) ### Changed - Elegantly handle missing/undefined methods with `have_attributes` matcher. diff --git a/src/spectator/matchers/reference_matcher.cr b/src/spectator/matchers/reference_matcher.cr index 8385eb6..2344527 100644 --- a/src/spectator/matchers/reference_matcher.cr +++ b/src/spectator/matchers/reference_matcher.cr @@ -14,7 +14,9 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : Expression(T)) : Bool forall T value = expected.value - if value && value.responds_to?(:same?) + if value.nil? + actual.value.nil? + elsif value.responds_to?(:same?) value.same?(actual.value) else # Value type (struct) comparison.