Store expected value as array

Fixes issue where contain_exactly matcher would try to append to a tuple 
(which isn't allowed).
This commit is contained in:
Michael Miller 2020-05-28 22:23:29 -06:00
parent c99401f7d5
commit 476e54bb2b
3 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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?

View file

@ -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?