From 16a2204a2d4482ae876afcbc6deb00d3040af616 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 1 Aug 2019 16:17:39 -0600 Subject: [PATCH] Simplify CaseMatcher by using new matcher refactoring --- src/spectator/matchers/case_matcher.cr | 41 ++++++-------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/src/spectator/matchers/case_matcher.cr b/src/spectator/matchers/case_matcher.cr index 8aa727c..b24d9df 100644 --- a/src/spectator/matchers/case_matcher.cr +++ b/src/spectator/matchers/case_matcher.cr @@ -4,43 +4,20 @@ module Spectator::Matchers # Common matcher that tests whether two values semantically equal each other. # The values are compared with the === operator. struct CaseMatcher(ExpectedType) < ValueMatcher(ExpectedType) - # Determines whether the matcher is satisfied with the value given to it. private def match?(actual) - expected === actual + expected.value === actual.value + end + + def description + "matches #{expected.label}" end - # Determines whether the matcher is satisfied with the partial given to it. - def match(partial, negated = false) - values = ExpectedActual.new(partial, self) - MatchData.new(match?(values.actual), values) + def failure_message(actual) + "#{actual.label} did not match #{expected.label}" end - # Match data specific to this matcher. - private struct MatchData(ExpectedType, ActualType) < MatchData - # Creates the match data. - def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType)) - super(matched) - end - - # Information about the match. - def named_tuple - { - expected: NegatableMatchDataValue.new(@values.expected), - actual: @values.actual, - } - end - - # Describes the condition that satisfies the matcher. - # This is informational and displayed to the end-user. - def message - "#{@values.actual_label} matches #{@values.expected_label}" - end - - # Describes the condition that won't satsify the matcher. - # This is informational and displayed to the end-user. - def negated_message - "#{@values.actual_label} does not match #{@values.expected_label}" - end + def failure_message_when_negated(actual) + "#{actual.label} matched #{expected.label}" end end end