Add missing methods to matchers

Fix matcher inheritance.
This commit is contained in:
Michael Miller 2019-08-08 17:03:47 -06:00
parent 9bffb30041
commit 1222e24836
3 changed files with 25 additions and 1 deletions

View file

@ -15,6 +15,14 @@ module Spectator::Matchers
def initialize(@expected : TestValue(ExpectedType))
end
def description
if (message = @expected)
"raises #{ExceptionType} with message #{message}"
else
"raises #{ExceptionType}"
end
end
def match(actual)
exception = capture_exception { actual.value }
case exception

View file

@ -34,6 +34,14 @@ module Spectator::Matchers
end
end
private def failure_message(actual)
"#{actual.label} does not have #{expected.label}"
end
private def failure_message_when_negated(actual)
"#{actual.label} has #{expected.label}"
end
# Captures all of the actual values.
# A `NamedTuple` is returned, with each key being the attribute.
private def snapshot_values(object)

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The `ExpectedType` type param should be a `NamedTuple`.
# Each key in the tuple is a predicate (without the '?') to test.
# Each value is a a `Tuple` of arguments to pass to the predicate method.
struct PredicateMatcher(ExpectedType) < Matcher(ExpectedType)
struct PredicateMatcher(ExpectedType) < Matcher
private getter expected
def initialize(@expected : TestValue(ExpectedType))
@ -33,6 +33,14 @@ module Spectator::Matchers
end
end
private def failure_message(actual)
"#{actual.label} is not #{expected.label}"
end
private def failure_message_when_negated(actual)
"#{actual.label} is #{expected.label}"
end
# Captures all of the actual values.
# A `NamedTuple` is returned, with each key being the attribute.
private def snapshot_values(object)