From 76c21d447ae20b07cd334c19ba0c526bd58ed0a3 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 16 Nov 2019 08:49:09 -0700 Subject: [PATCH] Coerce operations in match? to booleans The compiler is merging null-doubles with these matchers. Methods that normally return a boolean instead return the instance (self). This causes a return type-mismatch. There should be a better alternative to this. --- src/spectator/matchers/case_matcher.cr | 2 +- src/spectator/matchers/collection_matcher.cr | 2 +- src/spectator/matchers/contain_matcher.cr | 2 +- src/spectator/matchers/empty_matcher.cr | 2 +- src/spectator/matchers/equality_matcher.cr | 2 +- src/spectator/matchers/greater_than_equal_matcher.cr | 2 +- src/spectator/matchers/greater_than_matcher.cr | 2 +- src/spectator/matchers/have_key_matcher.cr | 2 +- src/spectator/matchers/have_matcher.cr | 8 ++++---- src/spectator/matchers/have_value_matcher.cr | 2 +- src/spectator/matchers/inequality_matcher.cr | 2 +- src/spectator/matchers/less_than_equal_matcher.cr | 2 +- src/spectator/matchers/less_than_matcher.cr | 2 +- src/spectator/matchers/nil_matcher.cr | 2 +- src/spectator/matchers/range_matcher.cr | 2 +- src/spectator/matchers/reference_matcher.cr | 2 +- src/spectator/matchers/size_matcher.cr | 2 +- src/spectator/matchers/size_of_matcher.cr | 2 +- src/spectator/matchers/type_matcher.cr | 2 +- 19 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/spectator/matchers/case_matcher.cr b/src/spectator/matchers/case_matcher.cr index e7f0891..070bf2e 100644 --- a/src/spectator/matchers/case_matcher.cr +++ b/src/spectator/matchers/case_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value === actual.value + !!(expected.value === actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/collection_matcher.cr b/src/spectator/matchers/collection_matcher.cr index 44f2ee8..154d54f 100644 --- a/src/spectator/matchers/collection_matcher.cr +++ b/src/spectator/matchers/collection_matcher.cr @@ -14,7 +14,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value.includes?(actual.value) + !!expected.value.includes?(actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/contain_matcher.cr b/src/spectator/matchers/contain_matcher.cr index 26d3287..9dfebb0 100644 --- a/src/spectator/matchers/contain_matcher.cr +++ b/src/spectator/matchers/contain_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value.all? do |item| + !!expected.value.all? do |item| actual.value.includes?(item) end end diff --git a/src/spectator/matchers/empty_matcher.cr b/src/spectator/matchers/empty_matcher.cr index c64c6d7..3bf4659 100644 --- a/src/spectator/matchers/empty_matcher.cr +++ b/src/spectator/matchers/empty_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value.empty? + !!actual.value.empty? end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/equality_matcher.cr b/src/spectator/matchers/equality_matcher.cr index bcdcd44..911055d 100644 --- a/src/spectator/matchers/equality_matcher.cr +++ b/src/spectator/matchers/equality_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value == actual.value + !!(expected.value == actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/greater_than_equal_matcher.cr b/src/spectator/matchers/greater_than_equal_matcher.cr index 08eb88c..b2b2dfc 100644 --- a/src/spectator/matchers/greater_than_equal_matcher.cr +++ b/src/spectator/matchers/greater_than_equal_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value >= expected.value + !!(actual.value >= expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/greater_than_matcher.cr b/src/spectator/matchers/greater_than_matcher.cr index 5dfc90c..c69edc6 100644 --- a/src/spectator/matchers/greater_than_matcher.cr +++ b/src/spectator/matchers/greater_than_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value > expected.value + !!(actual.value > expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/have_key_matcher.cr b/src/spectator/matchers/have_key_matcher.cr index c579930..36488e3 100644 --- a/src/spectator/matchers/have_key_matcher.cr +++ b/src/spectator/matchers/have_key_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value.has_key?(expected.value) + !!actual.value.has_key?(expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/have_matcher.cr b/src/spectator/matchers/have_matcher.cr index d67eb35..5ec688b 100644 --- a/src/spectator/matchers/have_matcher.cr +++ b/src/spectator/matchers/have_matcher.cr @@ -23,17 +23,17 @@ module Spectator::Matchers # Checks if a `String` matches the expected values. # The `includes?` method is used for this check. - private def match_string?(value) - expected.value.all? do |item| + private def match_string?(value) : Bool + !!expected.value.all? do |item| value.includes?(item) end end # Checks if an `Enumerable` matches the expected values. # The `===` operator is used on every item. - private def match_enumerable?(value) + private def match_enumerable?(value) : Bool array = value.to_a - expected.value.all? do |item| + !!expected.value.all? do |item| array.any? do |element| item === element end diff --git a/src/spectator/matchers/have_value_matcher.cr b/src/spectator/matchers/have_value_matcher.cr index 1f3e4a9..6bc4b5a 100644 --- a/src/spectator/matchers/have_value_matcher.cr +++ b/src/spectator/matchers/have_value_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value.has_value?(expected.value) + !!actual.value.has_value?(expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/inequality_matcher.cr b/src/spectator/matchers/inequality_matcher.cr index f721ab4..a2d65ed 100644 --- a/src/spectator/matchers/inequality_matcher.cr +++ b/src/spectator/matchers/inequality_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value != actual.value + !!(expected.value != actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/less_than_equal_matcher.cr b/src/spectator/matchers/less_than_equal_matcher.cr index bc56dab..9b53d5e 100644 --- a/src/spectator/matchers/less_than_equal_matcher.cr +++ b/src/spectator/matchers/less_than_equal_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value <= expected.value + !!(actual.value <= expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/less_than_matcher.cr b/src/spectator/matchers/less_than_matcher.cr index 4e14cd4..1a2811c 100644 --- a/src/spectator/matchers/less_than_matcher.cr +++ b/src/spectator/matchers/less_than_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value < expected.value + !!(actual.value < expected.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/nil_matcher.cr b/src/spectator/matchers/nil_matcher.cr index 5334037..d21293b 100644 --- a/src/spectator/matchers/nil_matcher.cr +++ b/src/spectator/matchers/nil_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value.nil? + !!actual.value.nil? end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/range_matcher.cr b/src/spectator/matchers/range_matcher.cr index 32d491f..ac13310 100644 --- a/src/spectator/matchers/range_matcher.cr +++ b/src/spectator/matchers/range_matcher.cr @@ -27,7 +27,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value.includes?(actual.value) + !!expected.value.includes?(actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/reference_matcher.cr b/src/spectator/matchers/reference_matcher.cr index 3586e14..a5a9c3c 100644 --- a/src/spectator/matchers/reference_matcher.cr +++ b/src/spectator/matchers/reference_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value.same?(actual.value) + !!expected.value.same?(actual.value) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/size_matcher.cr b/src/spectator/matchers/size_matcher.cr index d309849..3ea6b17 100644 --- a/src/spectator/matchers/size_matcher.cr +++ b/src/spectator/matchers/size_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value == actual.value.size + !!(expected.value == actual.value.size) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/size_of_matcher.cr b/src/spectator/matchers/size_of_matcher.cr index 0d7bc30..3c6944c 100644 --- a/src/spectator/matchers/size_of_matcher.cr +++ b/src/spectator/matchers/size_of_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - expected.value.size == actual.value.size + !!(expected.value.size == actual.value.size) end # Message displayed when the matcher isn't satisifed. diff --git a/src/spectator/matchers/type_matcher.cr b/src/spectator/matchers/type_matcher.cr index 4b7aff3..1835acb 100644 --- a/src/spectator/matchers/type_matcher.cr +++ b/src/spectator/matchers/type_matcher.cr @@ -13,7 +13,7 @@ module Spectator::Matchers # Checks whether the matcher is satisifed with the expression given to it. private def match?(actual : TestExpression(T)) : Bool forall T - actual.value.is_a?(Expected) + !!actual.value.is_a?(Expected) end # Message displayed when the matcher isn't satisifed.