From 476e54bb2b412dab94d89cad0ccc227995f7289d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 28 May 2020 22:23:29 -0600 Subject: [PATCH] Store expected value as array Fixes issue where contain_exactly matcher would try to append to a tuple (which isn't allowed). --- src/spectator/dsl/matchers.cr | 6 +++--- src/spectator/matchers/array_matcher.cr | 6 +++--- src/spectator/matchers/unordered_array_matcher.cr | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/spectator/dsl/matchers.cr b/src/spectator/dsl/matchers.cr index b533c5a..3a2a703 100644 --- a/src/spectator/dsl/matchers.cr +++ b/src/spectator/dsl/matchers.cr @@ -548,7 +548,7 @@ module Spectator # expect([1, 2, 3]).to contain_exactly(3, 2, 1) # ``` macro contain_exactly(*expected) - %test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}}) + %test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}}) ::Spectator::Matchers::ArrayMatcher.new(%test_value) end @@ -560,7 +560,7 @@ module Spectator # expect([1, 2, 3]).to match_array([3, 2, 1]) # ``` macro match_array(expected) - %test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}}) + %test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}}) ::Spectator::Matchers::ArrayMatcher.new(%test_value) end @@ -582,7 +582,7 @@ module Spectator # expect([1, 2, 3]).to have_size_of(%i[x y z]) # ``` macro have_size_of(expected) - %test_value = ::Spectator::TestValue.new(({{expected}}), {{expected.stringify}}) + %test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}}) ::Spectator::Matchers::SizeOfMatcher.new(%test_value) end diff --git a/src/spectator/matchers/array_matcher.cr b/src/spectator/matchers/array_matcher.cr index 6b2010a..2f0d264 100644 --- a/src/spectator/matchers/array_matcher.cr +++ b/src/spectator/matchers/array_matcher.cr @@ -11,7 +11,7 @@ module Spectator::Matchers private getter expected # Creates the matcher with an expected value. - def initialize(@expected : TestValue(ExpectedType)) + def initialize(@expected : TestValue(Array(ExpectedType))) end # Short text about the matcher's purpose. @@ -27,7 +27,7 @@ module Spectator::Matchers return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a) actual_elements = actual_value.to_a - expected_elements = expected.value.to_a + expected_elements = expected.value missing, extra = compare_arrays(expected_elements, actual_elements) if missing.empty? && extra.empty? @@ -51,7 +51,7 @@ module Spectator::Matchers return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a) actual_elements = actual_value.to_a - expected_elements = expected.value.to_a + expected_elements = expected.value missing, extra = compare_arrays(expected_elements, actual_elements) if missing.empty? && extra.empty? diff --git a/src/spectator/matchers/unordered_array_matcher.cr b/src/spectator/matchers/unordered_array_matcher.cr index 6c964fc..e408809 100644 --- a/src/spectator/matchers/unordered_array_matcher.cr +++ b/src/spectator/matchers/unordered_array_matcher.cr @@ -8,7 +8,7 @@ module Spectator::Matchers private getter expected # Creates the matcher with an expected value. - def initialize(@expected : TestValue(ExpectedType)) + def initialize(@expected : TestValue(Array(ExpectedType))) end # Short text about the matcher's purpose. @@ -24,7 +24,7 @@ module Spectator::Matchers return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a) actual_elements = actual_value.to_a - expected_elements = expected.value.to_a + expected_elements = expected.value missing, extra = array_diff(expected_elements, actual_elements) if missing.empty? && extra.empty? @@ -46,7 +46,7 @@ module Spectator::Matchers return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a) actual_elements = actual_value.to_a - expected_elements = expected.value.to_a + expected_elements = expected.value missing, extra = array_diff(expected_elements, actual_elements) if missing.empty? && extra.empty?