mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Condense expected and actual values and labels
Created a new struct specifically to store expected and actual valuesand their user labels.
This commit is contained in:
parent
520901332e
commit
4c7e8a3225
2 changed files with 27 additions and 6 deletions
|
@ -9,34 +9,35 @@ module Spectator::Matchers
|
||||||
def match(partial) : MatchData
|
def match(partial) : MatchData
|
||||||
actual = partial.actual
|
actual = partial.actual
|
||||||
matched = actual == expected
|
matched = actual == expected
|
||||||
MatchData.new(matched, expected, actual, partial.label, label)
|
values = ExpectedActual.new(expected, label, actual, partial.label)
|
||||||
|
MatchData.new(matched, values)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Match data specific to this matcher.
|
# Match data specific to this matcher.
|
||||||
private struct MatchData(ExpectedType, ActualType) < MatchData
|
private struct MatchData(ExpectedType, ActualType) < MatchData
|
||||||
# Creates the match data.
|
# Creates the match data.
|
||||||
def initialize(matched, @expected : ExpectedType, @actual : ActualType, @expected_label : String, @actual_label : String)
|
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
|
||||||
super(matched)
|
super(matched)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Information about the match.
|
# Information about the match.
|
||||||
def values
|
def values
|
||||||
{
|
{
|
||||||
expected: @expected,
|
expected: @values.expected,
|
||||||
actual: @actual,
|
actual: @values.actual,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Describes the condition that satisfies the matcher.
|
# Describes the condition that satisfies the matcher.
|
||||||
# This is informational and displayed to the end-user.
|
# This is informational and displayed to the end-user.
|
||||||
def message
|
def message
|
||||||
"#{@expected_label} is #{@actual_label} (using ==)"
|
"#{@values.expected_label} is #{@values.actual_label} (using ==)"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Describes the condition that won't satsify the matcher.
|
# Describes the condition that won't satsify the matcher.
|
||||||
# This is informational and displayed to the end-user.
|
# This is informational and displayed to the end-user.
|
||||||
def negated_message
|
def negated_message
|
||||||
"#{@expected_label} is not #{@actual_label} (using ==)"
|
"#{@values.expected_label} is not #{@values.actual_label} (using ==)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
20
src/spectator/matchers/expected_actual.cr
Normal file
20
src/spectator/matchers/expected_actual.cr
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module Spectator::Matchers
|
||||||
|
# Stores values and labels for expected and actual values.
|
||||||
|
private struct ExpectedActual(ExpectedType, ActualType)
|
||||||
|
# The expected value.
|
||||||
|
getter expected : ExpectedType
|
||||||
|
|
||||||
|
# The user label for the expected value.
|
||||||
|
getter expected_label : String
|
||||||
|
|
||||||
|
# The actual value.
|
||||||
|
getter actual : ActualType
|
||||||
|
|
||||||
|
# The user label for the actual value.
|
||||||
|
getter actual_label : String
|
||||||
|
|
||||||
|
# Creates the value and label store.
|
||||||
|
def initialize(@expected : ExpectedType, @expected_label, @actual : ActualType, @actual_label)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue