class RuboCop::Cop::Chef::Deprecations::DeprecatedChefSpecPlatform

Use currently supported platforms in ChefSpec listed at github.com/chefspec/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

legacy_chefspec_platform(platform, version) click to toggle source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 93
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
on_send(node) click to toggle source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 114
def on_send(node)
  chefspec_definition?(node) do |plat, ver|
    next unless legacy_chefspec_platform(plat.value, ver.value)
    add_offense(node, message: MSG, severity: :warning) do |corrector|
      if replacement = replacement_string(plat.value, ver.value) # rubocop: disable Lint/AssignmentInCondition
        corrector.replace(ver, "'#{replacement}'")
      end
    end
  end
end
replacement_string(platform, version) click to toggle source
# File lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb, line 104
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