mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Condense the ExpectedActual initializer
Made label and expected value public.
This commit is contained in:
parent
4c7e8a3225
commit
8cc66b538f
4 changed files with 19 additions and 6 deletions
|
@ -4,13 +4,16 @@ module Spectator::Matchers
|
|||
# Common matcher that tests whether two values equal each other.
|
||||
# The values are compared with the == operator.
|
||||
struct EqualityMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||
# Determines whether the matcher is satisfied with the value given to it.
|
||||
private def match?(actual)
|
||||
actual == expected
|
||||
end
|
||||
|
||||
# Determines whether the matcher is satisfied with the partial given to it.
|
||||
# `MatchData` is returned that contains information about the match.
|
||||
def match(partial) : MatchData
|
||||
actual = partial.actual
|
||||
matched = actual == expected
|
||||
values = ExpectedActual.new(expected, label, actual, partial.label)
|
||||
MatchData.new(matched, values)
|
||||
values = ExpectedActual.new(partial, self)
|
||||
MatchData.new(match?(values.actual), values)
|
||||
end
|
||||
|
||||
# Match data specific to this matcher.
|
||||
|
|
|
@ -16,5 +16,15 @@ module Spectator::Matchers
|
|||
# Creates the value and label store.
|
||||
def initialize(@expected : ExpectedType, @expected_label, @actual : ActualType, @actual_label)
|
||||
end
|
||||
|
||||
# Creates the value and label store.
|
||||
# Attributes are pulled from an expectation partial and matcher.
|
||||
def initialize(
|
||||
partial : Spectator::Expectations::ValueExpectationPartial(ActualType) |
|
||||
Spectator::Expectations::BlockExpectationPartial(ActualType),
|
||||
matcher : ValueMatcher(ExpectedType)
|
||||
)
|
||||
initialize(matcher.expected, matcher.label, partial.actual, partial.label)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module Spectator::Matchers
|
|||
# Textual representation of what the matcher expects.
|
||||
# This shouldn't be used in the conditional logic,
|
||||
# but for verbose output to help the end-user.
|
||||
private getter label : String
|
||||
getter label : String
|
||||
|
||||
# Creates the base of the matcher.
|
||||
def initialize(@label)
|
||||
|
|
|
@ -7,7 +7,7 @@ module Spectator::Matchers
|
|||
abstract struct ValueMatcher(ExpectedType) < Matcher
|
||||
# Expected value.
|
||||
# Sub-types may use this value to test the expectation and generate message strings.
|
||||
private getter expected
|
||||
getter expected
|
||||
|
||||
# Creates the value matcher.
|
||||
# The label should be a string representation of the expectation.
|
||||
|
|
Loading…
Reference in a new issue