From a633d41faee52c5e1f0b48ee15122686de14f45c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 31 Jan 2019 13:34:09 -0700 Subject: [PATCH] Move #eval to base class Code is identical across sub-classes. --- src/spectator/expectations/block_expectation_partial.cr | 6 ------ src/spectator/expectations/expectation_partial.cr | 5 ++++- src/spectator/expectations/value_expectation_partial.cr | 6 ------ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/spectator/expectations/block_expectation_partial.cr b/src/spectator/expectations/block_expectation_partial.cr index 2454926..18c27dc 100644 --- a/src/spectator/expectations/block_expectation_partial.cr +++ b/src/spectator/expectations/block_expectation_partial.cr @@ -21,11 +21,5 @@ module Spectator::Expectations protected def initialize(@block : -> ReturnType) super(@block.to_s) end - - # Evaluates the expectation and returns it. - private def eval(matcher, negated = false) : Expectation - matched = matcher.match?(self) - Expectation.new(matched, negated, self, matcher) - end end end diff --git a/src/spectator/expectations/expectation_partial.cr b/src/spectator/expectations/expectation_partial.cr index 83a0093..a012787 100644 --- a/src/spectator/expectations/expectation_partial.cr +++ b/src/spectator/expectations/expectation_partial.cr @@ -40,7 +40,10 @@ module Spectator::Expectations end # Evaluates the expectation and returns it. - private abstract def eval(matcher, negated = false) : Expectation + private def eval(matcher, negated = false) + matched = matcher.match?(self) + Expectation.new(matched, negated, self, matcher) + end # Reports an expectation to the current harness. private def report(expectation : Expectation) diff --git a/src/spectator/expectations/value_expectation_partial.cr b/src/spectator/expectations/value_expectation_partial.cr index f466cb9..9b8b648 100644 --- a/src/spectator/expectations/value_expectation_partial.cr +++ b/src/spectator/expectations/value_expectation_partial.cr @@ -20,11 +20,5 @@ module Spectator::Expectations protected def initialize(@actual : ActualType) super(@actual.to_s) end - - # Evaluates the expectation and returns it. - private def eval(matcher, negated = false) : Expectation - matched = matcher.match?(self) - Expectation.new(matched, negated, self, matcher) - end end end