mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Workaround typing issues
This commit is contained in:
parent
7868755eee
commit
590d81979e
2 changed files with 17 additions and 13 deletions
|
@ -23,7 +23,8 @@ module Spectator::Matchers
|
||||||
|
|
||||||
# Actually performs the test against the expression.
|
# Actually performs the test against the expression.
|
||||||
def match(actual : TestExpression(T)) : MatchData forall T
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:ends_with?)
|
value = actual.value
|
||||||
|
if value.is_a?(String) || value.responds_to?(:ends_with?)
|
||||||
match_ends_with(value, actual.label)
|
match_ends_with(value, actual.label)
|
||||||
else
|
else
|
||||||
match_last(value, actual.label)
|
match_last(value, actual.label)
|
||||||
|
@ -33,10 +34,11 @@ module Spectator::Matchers
|
||||||
# Performs the test against the expression, but inverted.
|
# Performs the test against the expression, but inverted.
|
||||||
# A successful match with `#match` should normally fail for this method, and vice-versa.
|
# A successful match with `#match` should normally fail for this method, and vice-versa.
|
||||||
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if actual.value.responds_to?(:ends_with?)
|
value = actual.value
|
||||||
negated_match_ends_with(actual)
|
if value.is_a?(String) || value.responds_to?(:ends_with?)
|
||||||
|
negated_match_ends_with(value, actual.label)
|
||||||
else
|
else
|
||||||
negated_match_last(actual)
|
negated_match_last(value, actual.label)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,11 +74,11 @@ module Spectator::Matchers
|
||||||
|
|
||||||
# Checks whether the actual value does not end with the expected value.
|
# Checks whether the actual value does not end with the expected value.
|
||||||
# This method expects (and uses) the `#ends_with?` method on the value.
|
# This method expects (and uses) the `#ends_with?` method on the value.
|
||||||
private def negated_match_ends_with(actual)
|
private def negated_match_ends_with(actual_value, actual_label)
|
||||||
if actual.value.ends_with?(expected.value)
|
if actual_value.ends_with?(expected.value)
|
||||||
FailedMatchData.new(description, "#{actual.label} ends with #{expected.label} (using #ends_with?)",
|
FailedMatchData.new(description, "#{actual_label} ends with #{expected.label} (using #ends_with?)",
|
||||||
expected: expected.value.inspect,
|
expected: expected.value.inspect,
|
||||||
actual: actual.value.inspect
|
actual: actual_value.inspect
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
SuccessfulMatchData.new(description)
|
SuccessfulMatchData.new(description)
|
||||||
|
@ -85,12 +87,12 @@ module Spectator::Matchers
|
||||||
|
|
||||||
# Checks whether the last element of the value is not the expected value.
|
# Checks whether the last element of the value is not the expected value.
|
||||||
# This method expects that the actual value is a set (enumerable).
|
# This method expects that the actual value is a set (enumerable).
|
||||||
private def negated_match_last(actual)
|
private def negated_match_last(actual_value, actual_label)
|
||||||
list = actual.value.to_a
|
list = actual_value.to_a
|
||||||
last = list.last
|
last = list.last
|
||||||
|
|
||||||
if expected.value === last
|
if expected.value === last
|
||||||
FailedMatchData.new(description, "#{actual.label} ends with #{expected.label} (using expected === last)",
|
FailedMatchData.new(description, "#{actual_label} ends with #{expected.label} (using expected === last)",
|
||||||
expected: expected.value.inspect,
|
expected: expected.value.inspect,
|
||||||
actual: last.inspect,
|
actual: last.inspect,
|
||||||
list: list.inspect
|
list: list.inspect
|
||||||
|
|
|
@ -22,7 +22,8 @@ module Spectator::Matchers
|
||||||
|
|
||||||
# Actually performs the test against the expression.
|
# Actually performs the test against the expression.
|
||||||
def match(actual : TestExpression(T)) : MatchData forall T
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:starts_with?)
|
value = actual.value
|
||||||
|
if value.is_a?(String) || value.responds_to?(:starts_with?)
|
||||||
match_starts_with(value, actual.label)
|
match_starts_with(value, actual.label)
|
||||||
else
|
else
|
||||||
match_first(value, actual.label)
|
match_first(value, actual.label)
|
||||||
|
@ -32,7 +33,8 @@ module Spectator::Matchers
|
||||||
# Performs the test against the expression, but inverted.
|
# Performs the test against the expression, but inverted.
|
||||||
# A successful match with `#match` should normally fail for this method, and vice-versa.
|
# A successful match with `#match` should normally fail for this method, and vice-versa.
|
||||||
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:starts_with?)
|
value = actual.value
|
||||||
|
if value.is_a?(String) || value.responds_to?(:starts_with?)
|
||||||
negated_match_starts_with(value, actual.label)
|
negated_match_starts_with(value, actual.label)
|
||||||
else
|
else
|
||||||
negated_match_first(value, actual.label)
|
negated_match_first(value, actual.label)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue