mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix some more matcher errors
This commit is contained in:
parent
8fc3af075c
commit
85b7412436
3 changed files with 20 additions and 10 deletions
|
@ -14,7 +14,7 @@ module Spectator::DSL
|
|||
# expect(1 + 2).to eq(3)
|
||||
# ```
|
||||
macro eq(expected)
|
||||
::Spectator::Matchers::EqualityMatcher.new(::Spectator::TestValue.new({{expected}}, {{expected.stringify}})))
|
||||
::Spectator::Matchers::EqualityMatcher.new(::Spectator::TestValue.new({{expected}}, {{expected.stringify}}))
|
||||
end
|
||||
|
||||
# Indicates that some value should not equal another.
|
||||
|
|
|
@ -22,12 +22,12 @@ module Spectator::Matchers
|
|||
index = compare_arrays(expected_elements, actual_elements)
|
||||
|
||||
case index
|
||||
when Int # Content differs.
|
||||
failed_content_mismatch(expected_elements, actual_elements, index, actual.label)
|
||||
when true # Contents are identical.
|
||||
SuccessfulMatchData.new
|
||||
when false # Size differs.
|
||||
else # Size differs.
|
||||
failed_size_mismatch(expected_elements, actual_elements, actual.label)
|
||||
else # Content differs.
|
||||
failed_content_mismatch(expected_elements, actual_elements, index, actual.label)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,11 +36,11 @@ module Spectator::Matchers
|
|||
expected_elements = expected.value.to_a
|
||||
|
||||
case compare_arrays(expected_elements, actual_elements)
|
||||
when Int # Contents differ.
|
||||
SuccessfulMatchData.new
|
||||
when true # Contents are identical.
|
||||
failed_content_identical(expected_elements, actual_elements, actual.label)
|
||||
when false # Size differs.
|
||||
SuccessfulMatchData.new
|
||||
else # Contents differ.
|
||||
else # Size differs.
|
||||
SuccessfulMatchData.new
|
||||
end
|
||||
end
|
||||
|
@ -84,7 +84,7 @@ module Spectator::Matchers
|
|||
end
|
||||
|
||||
private def failed_content_identical(expected_elements, actual_elements, actual_label)
|
||||
FailedMatchData.new("#{actual.label} contains exactly #{expected.label}",
|
||||
FailedMatchData.new("#{actual_label} contains exactly #{expected.label}",
|
||||
expected: "Not #{expected_elements.inspect}",
|
||||
actual: actual_elements.inspect
|
||||
)
|
||||
|
|
|
@ -21,14 +21,14 @@ module Spectator::Matchers
|
|||
if match?(snapshot)
|
||||
SuccessfulMatchData.new
|
||||
else
|
||||
FailedMatchData.new("#{actual.label} does not have #{expected.label}", **snapshot)
|
||||
FailedMatchData.new("#{actual.label} does not have #{expected.label}", **values(snapshot))
|
||||
end
|
||||
end
|
||||
|
||||
def negated_match(actual)
|
||||
snapshot = snapshot_values(actual.value)
|
||||
if match?(snapshot)
|
||||
FailedMatchData.new("#{actual.label} has #{expected.label}", **snapshot)
|
||||
FailedMatchData.new("#{actual.label} has #{expected.label}", **values(snapshot))
|
||||
else
|
||||
SuccessfulMatchData.new
|
||||
end
|
||||
|
@ -54,6 +54,16 @@ module Spectator::Matchers
|
|||
{% end %}
|
||||
end
|
||||
|
||||
private def values(snapshot)
|
||||
{% begin %}
|
||||
{
|
||||
{% for attribute in ExpectedType.keys %}
|
||||
{{attribute}}: snapshot[{{attribute.symbolize}}].inspect,
|
||||
{% end %}
|
||||
}
|
||||
{% end %}
|
||||
end
|
||||
|
||||
private def match?(snapshot)
|
||||
# Test each predicate and immediately return false if one is false.
|
||||
{% for attribute in ExpectedType.keys %}
|
||||
|
|
Loading…
Reference in a new issue