mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Various other fixes
This commit is contained in:
parent
8b718f0bd0
commit
569faa0a2b
3 changed files with 9 additions and 13 deletions
|
@ -6,27 +6,25 @@ module Spectator::Matchers
|
||||||
# Otherwise, it expects an `Enumerable` and iterates over each item until === is true.
|
# Otherwise, it expects an `Enumerable` and iterates over each item until === is true.
|
||||||
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||||
private def match?(actual)
|
private def match?(actual)
|
||||||
actual_value = actual.value
|
if (value = actual.value).is_a?(String)
|
||||||
if actual_value.is_a?(String)
|
match_string?(value)
|
||||||
match_string(actual_value)
|
|
||||||
else
|
else
|
||||||
match_enumerable(actual_value)
|
match_enumerable?(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if a `String` matches the expected values.
|
# Checks if a `String` matches the expected values.
|
||||||
# The `includes?` method is used for this check.
|
# The `includes?` method is used for this check.
|
||||||
private def match_string?(actual_value)
|
private def match_string?(value)
|
||||||
expected.value.all? do |item|
|
expected.value.all? do |item|
|
||||||
actual_value.includes?(item)
|
value.includes?(item) if item.is_a?(Char | String)
|
||||||
actual_value.includes?(item) if item.is_a?(Char | String)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if an `Enumerable` matches the expected values.
|
# Checks if an `Enumerable` matches the expected values.
|
||||||
# The `===` operator is used on every item.
|
# The `===` operator is used on every item.
|
||||||
private def match_enumerable?(actual_value)
|
private def match_enumerable?(value)
|
||||||
array = actual_value.to_a
|
array = value.to_a
|
||||||
expected.value.all? do |item|
|
expected.value.all? do |item|
|
||||||
array.any? do |element|
|
array.any? do |element|
|
||||||
item === element
|
item === element
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Spectator::Matchers
|
||||||
if match?(actual)
|
if match?(actual)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
else
|
else
|
||||||
FailedMatchData.new(failure_message(actual), values(actual))
|
FailedMatchData.new(failure_message(actual), **values(actual))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ module Spectator::Matchers
|
||||||
if does_not_match?(actual)
|
if does_not_match?(actual)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
else
|
else
|
||||||
FailedMatchData.new(failure_message_when_negated(actual), negated_values(actual))
|
FailedMatchData.new(failure_message_when_negated(actual), **negated_values(actual))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,8 +33,6 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def match_last(actual)
|
|
||||||
list = actual.value.to_a
|
|
||||||
private def match_first(value, actual)
|
private def match_first(value, actual)
|
||||||
first = list.first
|
first = list.first
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue