From e1b4c3387afad6fdc3a150d5bf0f2464e6c1d32b Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Fri, 19 Apr 2024 11:29:54 -0700 Subject: [PATCH] Simplify select.map to filter_map This commit simplifies instances where map is called on a select call to instead use filter_map. --- spec/unit/functions/lookup_fixture_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/functions/lookup_fixture_spec.rb b/spec/unit/functions/lookup_fixture_spec.rb index 8d4a2c25197..44fb72ab1d1 100644 --- a/spec/unit/functions/lookup_fixture_spec.rb +++ b/spec/unit/functions/lookup_fixture_spec.rb @@ -47,7 +47,7 @@ def compile_and_get_notifications(code) Puppet[:code] = code node.environment.check_for_reparse catalog = block_given? ? compiler.compile { |cat| yield(compiler.topscope); cat } : compiler.compile - catalog.resources.map(&:ref).select { |r| r.start_with?('Notify[') }.map { |r| r[7..-2] } + catalog.resources.map(&:ref).filter_map { |r| r[7..-2] if r.start_with?('Notify[') } end # There is a fully configured 'production' environment in fixtures at this location @@ -376,7 +376,7 @@ def compile_and_get_notifications(code) Puppet[:code] = "include bad_data\nlookup('bad_data::b')" expect { compiler.compile }.to raise_error(Puppet::ParseError, /did not find a value for the name 'bad_data::b'/) end - warnings = logs.select { |log| log.level == :warning }.map { |log| log.message } + warnings = logs.filter_map { |log| log.message if log.level == :warning } expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module; got b") end @@ -390,7 +390,7 @@ def compile_and_get_notifications(code) PUPPET expect(resources).to include('module_c') end - warnings = logs.select { |log| log.level == :warning }.map { |log| log.message } + warnings = logs.filter_map { |log| log.message if log.level == :warning } expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module; got b") end