mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Update ValueMatcher to use Matcher's methods
This commit is contained in:
parent
114a4077f3
commit
f63697b019
1 changed files with 8 additions and 14 deletions
|
@ -3,28 +3,22 @@ require "./matcher"
|
||||||
module Spectator::Matchers
|
module Spectator::Matchers
|
||||||
# Category of matcher that uses a value.
|
# Category of matcher that uses a value.
|
||||||
# Matchers of this type expect that a SUT applies to the value in some way.
|
# Matchers of this type expect that a SUT applies to the value in some way.
|
||||||
# Sub-types must implement `Matcher#match?`, `Matcher#message`, and `Matcher#negated_message`.
|
|
||||||
abstract struct ValueMatcher(ExpectedType) < Matcher
|
abstract struct ValueMatcher(ExpectedType) < Matcher
|
||||||
# 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.
|
|
||||||
getter label
|
|
||||||
|
|
||||||
# Expected value.
|
# Expected value.
|
||||||
# Sub-types may use this value to test the expectation and generate message strings.
|
# Sub-types may use this value to test the expectation and generate message strings.
|
||||||
getter expected
|
getter expected : TestValue(ExpectedType)
|
||||||
|
|
||||||
# Creates the value matcher.
|
# Creates the value matcher.
|
||||||
# The label should be a string representation of the expectation.
|
|
||||||
# The expected value is stored for later use.
|
# The expected value is stored for later use.
|
||||||
def initialize(@expected : ExpectedType, @label : String)
|
def initialize(@expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates the value matcher.
|
private def values(actual) : Array(LabeledValue)
|
||||||
# The label is generated by calling `#to_s` on the expected value.
|
super(actual) << LabeledValue.new(expected.value.to_s, "expected")
|
||||||
# The expected value is stored for later use.
|
end
|
||||||
def initialize(expected : ExpectedType)
|
|
||||||
initialize(expected, expected.to_s)
|
private def negated_values(actual) : Array(LabeledValue)
|
||||||
|
super(actual) << LabeledValue.new("Not #{expected.value}", "expected")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue