diff --git a/src/spectator/matchers/value_matcher.cr b/src/spectator/matchers/value_matcher.cr index 9ffa6d8..9e821ef 100644 --- a/src/spectator/matchers/value_matcher.cr +++ b/src/spectator/matchers/value_matcher.cr @@ -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