diff --git a/src/spectator/expectations/value_expectation_partial.cr b/src/spectator/expectations/value_expectation_partial.cr index ddbee9a..09bf196 100644 --- a/src/spectator/expectations/value_expectation_partial.cr +++ b/src/spectator/expectations/value_expectation_partial.cr @@ -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 diff --git a/src/spectator/matchers/value_matcher.cr b/src/spectator/matchers/value_matcher.cr index 3073e53..f1c8785 100644 --- a/src/spectator/matchers/value_matcher.cr +++ b/src/spectator/matchers/value_matcher.cr @@ -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