mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Simplify match data values by using named tuples
This commit is contained in:
parent
e7b19ee591
commit
436c10cad6
10 changed files with 62 additions and 66 deletions
|
@ -1,4 +1,3 @@
|
||||||
require "../test_value"
|
|
||||||
require "./failed_match_data"
|
require "./failed_match_data"
|
||||||
require "./matcher"
|
require "./matcher"
|
||||||
require "./successful_match_data"
|
require "./successful_match_data"
|
||||||
|
@ -61,29 +60,26 @@ module Spectator::Matchers
|
||||||
|
|
||||||
private def failed_size_mismatch(expected_elements, actual_elements, actual_label)
|
private def failed_size_mismatch(expected_elements, actual_elements, actual_label)
|
||||||
FailedMatchData.new("#{actual_label} does not contain exactly #{expected.label} (size mismatch)",
|
FailedMatchData.new("#{actual_label} does not contain exactly #{expected.label} (size mismatch)",
|
||||||
[
|
expected: expected_elements.inspect,
|
||||||
LabeledValue.new(expected_elements.inspect, "expected"),
|
actual: actual_elements.inspect,
|
||||||
LabeledValue.new(actual_elements.inspect, "actual"),
|
"expected size": expected_elements.size.to_s,
|
||||||
LabeledValue.new(expected_elements.size, "expected size"),
|
"actual size": actual_elements.size.to_s
|
||||||
LabeledValue.new(actual_elements.size, "actual size"),
|
)
|
||||||
])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def failed_content_mismatch(expected_elements, actual_elements, index, actual_label)
|
private def failed_content_mismatch(expected_elements, actual_elements, index, actual_label)
|
||||||
FailedMatchData.new("#{actual_label} does not contain exactly #{expected.label} (element mismatch)",
|
FailedMatchData.new("#{actual_label} does not contain exactly #{expected.label} (element mismatch)",
|
||||||
[
|
expected: expected_elements[index].inspect,
|
||||||
LabeledValue.new(expected_elements[index].inspect, "expected"),
|
actual: actual_elements[index].inspect,
|
||||||
LabeledValue.new(actual_elements[index].inspect, "actual"),
|
index: index.to_s
|
||||||
LabeledValue.new(index.to_s, "index"),
|
)
|
||||||
])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def failed_content_identical(expected_elements, actual_elements, actual_label)
|
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}",
|
||||||
LabeledValue.new("Not #{expected_elements.inspect}", "expected"),
|
actual: actual_elements.inspect
|
||||||
LabeledValue.new(actual_elements.inspect, "actual"),
|
)
|
||||||
])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,11 +22,11 @@ module Spectator::Matchers
|
||||||
"#{actual.label} contains #{expected.label}"
|
"#{actual.label} contains #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual) : Array(LabeledValue)
|
private def values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new(expected.value.inspect, "subset"),
|
subset: expected.value.inspect,
|
||||||
LabeledValue.new(actual.value.inspect, "superset"),
|
superset: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,8 +20,8 @@ module Spectator::Matchers
|
||||||
"#{actual.label} is empty"
|
"#{actual.label} is empty"
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual) : Array(LabeledValue)
|
private def values(actual)
|
||||||
[LabeledValue.new(actual.value.inspect, "actual")]
|
{actual: actual.value.inspect}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
require "../test_value"
|
|
||||||
require "./match_data"
|
require "./match_data"
|
||||||
|
|
||||||
module Spectator::Matchers
|
module Spectator::Matchers
|
||||||
|
@ -9,9 +8,10 @@ module Spectator::Matchers
|
||||||
|
|
||||||
getter failure_message : String
|
getter failure_message : String
|
||||||
|
|
||||||
getter values : Array(LabeledValue)
|
getter values : Array(Tuple(Symbol, String))
|
||||||
|
|
||||||
def initialize(@failure_message, @values = [] of LabeledValue)
|
def initialize(@failure_message, **values)
|
||||||
|
@values = values.to_a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,17 +21,17 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual)
|
private def values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new(">= #{expected.value.inspect}", "expected"),
|
expected: ">= #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual)
|
private def negated_values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("< #{expected.value.inspect}", "expected"),
|
expected: "< #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,17 +21,17 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual)
|
private def values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("> #{expected.value.inspect}", "expected"),
|
expected: "> #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual)
|
private def negated_values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("<= #{expected.value.inspect}", "expected"),
|
expected: "<= #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,17 +21,17 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual)
|
private def values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("<= #{expected.value.inspect}", "expected"),
|
expected: "<= #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual)
|
private def negated_values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("> #{expected.value.inspect}", "expected"),
|
expected: "> #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,17 +21,17 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual)
|
private def values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new("< #{expected.value.inspect}", "expected"),
|
expected: "< #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual)
|
private def negated_values(actual)
|
||||||
[
|
{
|
||||||
LabeledValue.new(">= #{expected.value.inspect}", "expected"),
|
expected: ">= #{expected.value.inspect}",
|
||||||
LabeledValue.new(actual.value.inspect, "actual"),
|
actual: actual.value.inspect,
|
||||||
]
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,12 +32,12 @@ module Spectator::Matchers
|
||||||
!matches?(actual)
|
!matches?(actual)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual) : Array(LabeledValue)
|
private def values(actual)
|
||||||
[LabeledValue.new(actual.value.inspect, "actual")]
|
{actual: actual.value.inspect}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual) : Array(LabeledValue)
|
private def negated_values(actual)
|
||||||
values
|
values(actual)
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual)
|
||||||
|
|
|
@ -13,12 +13,12 @@ module Spectator::Matchers
|
||||||
def initialize(@expected)
|
def initialize(@expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def values(actual) : Array(LabeledValue)
|
private def values(actual)
|
||||||
super(actual) << LabeledValue.new(expected.value.inspect, "expected")
|
super.merge(expected: expected.value.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def negated_values(actual) : Array(LabeledValue)
|
private def negated_values(actual)
|
||||||
super(actual) << LabeledValue.new("Not #{expected.value.inspect}", "expected")
|
super.merge(expected: "Not #{expected.value.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue