From f3e50c6432b60e70db96ea568c3f770d7a14a745 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 28 Feb 2019 14:52:15 -0700 Subject: [PATCH] TruthyMatcher doesn't need to store a label Extend from Matcher instead of ValueMatcher to bypass storing the label. The "expected" value is still used, but is renamed to "truthy" and used for the label. --- src/spectator/matchers/truthy_matcher.cr | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/spectator/matchers/truthy_matcher.cr b/src/spectator/matchers/truthy_matcher.cr index 9d5feb3..3975416 100644 --- a/src/spectator/matchers/truthy_matcher.cr +++ b/src/spectator/matchers/truthy_matcher.cr @@ -8,19 +8,23 @@ module Spectator::Matchers # # Additionally, different matchers can be created # by using the `#<`, `#<=`, `#>`, `#>=`, `#==`, and `#!=` operators. - struct TruthyMatcher < ValueMatcher(Bool) + struct TruthyMatcher < Matcher # Creates the truthy matcher. # The *truthy* argument should be true to match "truthy" values, # and false to match "falsey" values. - def initialize(truthy : Bool) - super(truthy ? "truthy" : "falsey", truthy) + def initialize(@truthy : Bool) + end + + # Textual representation of what the matcher expects. + def label + @truthy ? "truthy" : "falsey" end # Determines whether the matcher is satisfied with the value given to it. # True is returned if the match was successful, false otherwise. def match?(partial) # Cast value to truthy value and compare. - @expected == !!partial.actual + @truthy == !!partial.actual end # Determines whether the matcher is satisfied with the partial given to it.