Better handling with be match against Value types and nil

Releates to https://github.com/icy-arctic-fox/spectator/issues/37
This commit is contained in:
Michael Miller 2021-09-28 18:22:41 -06:00
parent 99ced17516
commit a95c5bcab7
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
2 changed files with 4 additions and 1 deletions

View file

@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Fixed ### Fixed
- Fix usage of `be ===` and `be =~` [#34](https://github.com/icy-arctic-fox/spectator/issues/34) - 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 ### Changed
- Elegantly handle missing/undefined methods with `have_attributes` matcher. - Elegantly handle missing/undefined methods with `have_attributes` matcher.

View file

@ -14,7 +14,9 @@ module Spectator::Matchers
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : Expression(T)) : Bool forall T private def match?(actual : Expression(T)) : Bool forall T
value = expected.value value = expected.value
if value && value.responds_to?(:same?) if value.nil?
actual.value.nil?
elsif value.responds_to?(:same?)
value.same?(actual.value) value.same?(actual.value)
else else
# Value type (struct) comparison. # Value type (struct) comparison.