diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index 7d14334..803b18e 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -574,7 +574,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 + ::Spectator::Matchers::PredicateMatcher.new({ {{method_name}}: Tuple.new({{call.args.splat}}) }, {{method_name.stringify}}) {% 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 41f9f44..71d0229 100644 --- a/src/spectator/matchers/predicate_matcher.cr +++ b/src/spectator/matchers/predicate_matcher.cr @@ -4,7 +4,8 @@ module Spectator::Matchers # Matcher that tests one or more predicates (methods ending in '?'). # The `ExpectedType` type param should be a `NamedTuple`. # Each key in the tuple is a predicate (without the '?') to test. - struct PredicateMatcher(ExpectedType) < Matcher + # Each value is a a `Tuple` of arguments to pass to the predicate method. + struct PredicateMatcher(ExpectedType) < ValueMatcher(ExpectedType) # Textual representation of what the matcher expects. # Constructs the label from the type parameters. def label @@ -36,7 +37,7 @@ module Spectator::Matchers {% begin %} { {% for attribute in ExpectedType.keys %} - {{attribute}}: actual.{{attribute}}?, + {{attribute}}: actual.{{attribute}}?(*@expected[{{attribute.symbolize}}]), {% end %} } {% end %}