class RuboCop::Cop::Chef::Deprecations::DeprecatedChefSpecPlatform
Use currently supported platforms in ChefSpec listed at github.com/chef/fauxhai/blob/main/PLATFORMS.md. Fauxhai / ChefSpec will perform fuzzy matching on platform version values so it’s always best to be less specific ie. 10 instead of 10.3
@example
let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '14.04') }
Constants
- DEPRECATED_MAPPING
- MSG
Public Instance Methods
Source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 94 def legacy_chefspec_platform(platform, version) return false unless DEPRECATED_MAPPING.key?(platform) DEPRECATED_MAPPING[platform].each_pair do |match_string, replacement| return true if Gem::Dependency.new('', match_string.split(',')).match?('', version) && replacement != version # we want to catch '7.0' and suggest '7', but not alert on '7' end false end
Source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 115 def on_send(node) chefspec_definition?(node) do |plat, ver| next unless legacy_chefspec_platform(plat.value, ver.value) add_offense(node, severity: :warning) do |corrector| if replacement = replacement_string(plat.value, ver.value) # rubocop: disable Lint/AssignmentInCondition corrector.replace(ver, "'#{replacement}'") end end end end
Source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 105 def replacement_string(platform, version) DEPRECATED_MAPPING[platform].each_pair do |match_string, replacement| return replacement if Gem::Dependency.new('', match_string.split(',')).match?('', version) && replacement != version && # we want to catch '7.0' and suggest '7', but not alert on '7' replacement != true # true means it's busted, but requires human intervention to fix end nil # we don't have a replacement os return nil end