diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index 0c4cf1a..6d3a5f4 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -423,7 +423,7 @@ module Spectator::DSL macro method_missing(call) {% if call.name.starts_with?("be_") %} {% method_name = call.name[3..-1] %} # Remove `be_` prefix. - ::Spectator::Matchers::PredicateMatcher(NamedTuple({{method_name}}: Nil)).new({{method_name.stringify}}) + ::Spectator::Matchers::PredicateMatcher(NamedTuple({{method_name}}: Nil)).new {% else %} {% raise "Undefined local variable or method '#{call}'" %} {% end %} diff --git a/src/spectator/matchers/predicate_matcher.cr b/src/spectator/matchers/predicate_matcher.cr index 3332403..910d89e 100644 --- a/src/spectator/matchers/predicate_matcher.cr +++ b/src/spectator/matchers/predicate_matcher.cr @@ -5,6 +5,12 @@ module Spectator::Matchers # The `ExpectedType` type param should be a `NamedTuple`. # Each key in the tuple is a predicate (without the `?`) to test. struct PredicateMatcher(ExpectedType) < Matcher + # Creates the matcher. + # Constructs the label from the type parameters. + def initialize + super({{ExpectedType.keys.splat.stringify}}) + 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)