From 23230e8084029cff81dd359b232efacaf37f2dc8 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 27 Jun 2026 22:45:45 -0700 Subject: [PATCH] Use explicit MatchData captures instead of regex globals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SubscribesMatcher and NotificationsMatcher parsed their `type[name]` signature by calling String#match for its side effect and then reading the `$1`/`$2` global match variables. Capture the MatchData in a local and read match[1]/match[2] instead — clearer, thread-safe, and not dependent on hidden global state. Signed-off-by: Tim Smith --- lib/chefspec/matchers/notifications_matcher.rb | 6 +++--- lib/chefspec/matchers/subscribes_matcher.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/chefspec/matchers/notifications_matcher.rb b/lib/chefspec/matchers/notifications_matcher.rb index 8b31eaff..593be8a9 100644 --- a/lib/chefspec/matchers/notifications_matcher.rb +++ b/lib/chefspec/matchers/notifications_matcher.rb @@ -3,9 +3,9 @@ class NotificationsMatcher include ChefSpec::Normalize def initialize(signature) - signature.match(/^([^\[]*)\[(.*)\]$/) - @expected_resource_type = $1 - @expected_resource_name = $2 + match = signature.match(/^([^\[]*)\[(.*)\]$/) + @expected_resource_type = match[1] + @expected_resource_name = match[2] end def matches?(resource) diff --git a/lib/chefspec/matchers/subscribes_matcher.rb b/lib/chefspec/matchers/subscribes_matcher.rb index df40333b..10d13b7f 100644 --- a/lib/chefspec/matchers/subscribes_matcher.rb +++ b/lib/chefspec/matchers/subscribes_matcher.rb @@ -3,9 +3,9 @@ class SubscribesMatcher include ChefSpec::Normalize def initialize(signature) - signature.match(/^([^\[]*)\[(.*)\]$/) - @expected_resource_type = $1 - @expected_resource_name = $2 + match = signature.match(/^([^\[]*)\[(.*)\]$/) + @expected_resource_type = match[1] + @expected_resource_name = match[2] end def matches?(resource)