From 3b7ebba275f1cc2e88e775229e28b622bc67e286 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 27 Jun 2026 22:44:39 -0700 Subject: [PATCH] Add respond_to_missing? to ResourceMatcher ResourceMatcher#method_missing implements the dynamic `with_*` matcher sugar but had no matching respond_to_missing?, so `respond_to?(:with_x)` returned false and the object misrepresented its interface to introspection and serialization. Add respond_to_missing? mirroring the method_missing pattern, following the same approach already used in SoloRunner. Signed-off-by: Tim Smith --- lib/chefspec/matchers/resource_matcher.rb | 4 ++++ spec/unit/matchers/resource_matcher_spec.rb | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/chefspec/matchers/resource_matcher.rb b/lib/chefspec/matchers/resource_matcher.rb index 25b188b9..18b431fc 100644 --- a/lib/chefspec/matchers/resource_matcher.rb +++ b/lib/chefspec/matchers/resource_matcher.rb @@ -40,6 +40,10 @@ def method_missing(m, *args, &block) end end + def respond_to_missing?(m, include_private = false) + m.to_s.match?(/^with_(.+)$/) || super + end + def description %Q{#{@expected_action} #{@resource_name} "#{@expected_identity}"} end diff --git a/spec/unit/matchers/resource_matcher_spec.rb b/spec/unit/matchers/resource_matcher_spec.rb index aec15441..691ffcc4 100644 --- a/spec/unit/matchers/resource_matcher_spec.rb +++ b/spec/unit/matchers/resource_matcher_spec.rb @@ -1,5 +1,15 @@ require "spec_helper" describe ChefSpec::Matchers::ResourceMatcher do - pending + subject { described_class.new(:template, :create, "/etc/foo") } + + describe "#respond_to?" do + it "reports responding to dynamic with_* matcher methods" do + expect(subject).to respond_to(:with_owner) + end + + it "does not report responding to unrelated missing methods" do + expect(subject).not_to respond_to(:nonexistent_method) + end + end end