Move #eval to partial

This commit is contained in:
Michael Miller 2018-11-13 21:44:56 -07:00
parent a3ac50d661
commit 35b59854ec
2 changed files with 8 additions and 9 deletions

View file

@ -24,13 +24,13 @@ module Spectator::Expectations
# Asserts that the `#actual` value matches some criteria.
# The criteria is defined by the matcher passed to this method.
def to(matcher : Matchers::ValueMatcher(ExpectedType)) : Nil forall ExpectedType
report(matcher.eval(self))
report(eval(matcher))
end
# Asserts that the `#actual` value *does not* match some criteria.
# This is effectively the opposite of `#to`.
def to_not(matcher : Matchers::ValueMatcher(ExpectedType)) : Nil forall ExpectedType
report(matcher.eval(self, true))
report(eval(matcher, true))
end
# ditto
@ -38,5 +38,11 @@ module Spectator::Expectations
def not_to(matcher : Matchers::ValueMatcher(ExpectedType)) : Nil forall ExpectedType
to_not(matcher)
end
# Evaluates the expectation and returns it.
private def eval(matcher : Matchers::ValueMatcher(ExpectedType), negated = false) forall ExpectedType
matched = matcher.match?(self)
ValueExpectation.new(matched, negated, self, matcher)
end
end
end

View file

@ -24,13 +24,6 @@ module Spectator::Matchers
super(@expected.to_s)
end
# Determines whether the matcher is satisfied with the value given to it.
# An `Expectation` is returned containing all match information.
def eval(partial : ValueExpectationPartial(ActualType), negated = false) : Expectation forall ActualType
matched = match?(partial)
ValueExpectation.new(matched, negated, partial, self)
end
# Determines whether the matcher is satisfied with the value given to it.
# True is returned if the matcher is satisfied, false otherwise.
abstract def match?(partial : ValueExpectationPartial(ActualType)) : Bool forall ActualType