Skip to content

Commit 7a86ebf

Browse files
committed
Simplify select.map to filter_map
This commit simplifies instances where map is called on a select call to instead use filter_map.
1 parent d8bbc1e commit 7a86ebf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

spec/unit/functions/lookup_fixture_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def compile_and_get_notifications(code)
4747
Puppet[:code] = code
4848
node.environment.check_for_reparse
4949
catalog = block_given? ? compiler.compile { |cat| yield(compiler.topscope); cat } : compiler.compile
50-
catalog.resources.map(&:ref).select { |r| r.start_with?('Notify[') }.map { |r| r[7..-2] }
50+
catalog.resources.map(&:ref).filter_map { |r| r[7..-2] if r.start_with?('Notify[') }
5151
end
5252

5353
# There is a fully configured 'production' environment in fixtures at this location
@@ -376,7 +376,7 @@ def compile_and_get_notifications(code)
376376
Puppet[:code] = "include bad_data\nlookup('bad_data::b')"
377377
expect { compiler.compile }.to raise_error(Puppet::ParseError, /did not find a value for the name 'bad_data::b'/)
378378
end
379-
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
379+
warnings = logs.filter_map { |log| log.message if log.level == :warning }
380380
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")
381381
end
382382

@@ -390,7 +390,7 @@ def compile_and_get_notifications(code)
390390
PUPPET
391391
expect(resources).to include('module_c')
392392
end
393-
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
393+
warnings = logs.filter_map { |log| log.message if log.level == :warning }
394394
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")
395395
end
396396

0 commit comments

Comments
 (0)