Update ValueMatcher to use Matcher's methods

This commit is contained in:
Michael Miller 2019-08-01 15:59:29 -06:00
parent 114a4077f3
commit f63697b019

View file

@ -3,28 +3,22 @@ require "./matcher"
module Spectator::Matchers
# Category of matcher that uses a value.
# 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
# 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.
# Sub-types may use this value to test the expectation and generate message strings.
getter expected
getter expected : TestValue(ExpectedType)
# Creates the value matcher.
# The label should be a string representation of the expectation.
# The expected value is stored for later use.
def initialize(@expected : ExpectedType, @label : String)
def initialize(@expected)
end
# Creates the value matcher.
# The label is generated by calling `#to_s` on the expected value.
# The expected value is stored for later use.
def initialize(expected : ExpectedType)
initialize(expected, expected.to_s)
private def values(actual) : Array(LabeledValue)
super(actual) << LabeledValue.new(expected.value.to_s, "expected")
end
private def negated_values(actual) : Array(LabeledValue)
super(actual) << LabeledValue.new("Not #{expected.value}", "expected")
end
end
end