Various other fixes

This commit is contained in:
Michael Miller 2019-08-09 00:42:39 -06:00
parent 8b718f0bd0
commit 569faa0a2b
3 changed files with 9 additions and 13 deletions

View File

@ -6,27 +6,25 @@ module Spectator::Matchers
# Otherwise, it expects an `Enumerable` and iterates over each item until === is true.
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
private def match?(actual)
actual_value = actual.value
if actual_value.is_a?(String)
match_string(actual_value)
if (value = actual.value).is_a?(String)
match_string?(value)
else
match_enumerable(actual_value)
match_enumerable?(value)
end
end
# Checks if a `String` matches the expected values.
# The `includes?` method is used for this check.
private def match_string?(actual_value)
private def match_string?(value)
expected.value.all? do |item|
actual_value.includes?(item)
actual_value.includes?(item) if item.is_a?(Char | String)
value.includes?(item) if item.is_a?(Char | String)
end
end
# Checks if an `Enumerable` matches the expected values.
# The `===` operator is used on every item.
private def match_enumerable?(actual_value)
array = actual_value.to_a
private def match_enumerable?(value)
array = value.to_a
expected.value.all? do |item|
array.any? do |element|
item === element

View File

@ -44,7 +44,7 @@ module Spectator::Matchers
if match?(actual)
SuccessfulMatchData.new
else
FailedMatchData.new(failure_message(actual), values(actual))
FailedMatchData.new(failure_message(actual), **values(actual))
end
end
@ -52,7 +52,7 @@ module Spectator::Matchers
if does_not_match?(actual)
SuccessfulMatchData.new
else
FailedMatchData.new(failure_message_when_negated(actual), negated_values(actual))
FailedMatchData.new(failure_message_when_negated(actual), **negated_values(actual))
end
end
end

View File

@ -33,8 +33,6 @@ module Spectator::Matchers
end
end
private def match_last(actual)
list = actual.value.to_a
private def match_first(value, actual)
first = list.first