Class: RuboCop::Cop::Chef::Modernize::DefinesChefSpecMatchers

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb

Overview

ChefSpec 7.1 and later auto generate ChefSpec matchers. Matchers in cookbooks can now be removed.

Examples:


### incorrect
if defined?(ChefSpec)
  def create_yum_repository(resource_name)
    ChefSpec::Matchers::ResourceMatcher.new(:yum_repository, :create, resource_name)
  end
end

Constant Summary collapse

MSG =
'ChefSpec matchers are now auto generated by ChefSpec 7.1+ and do not need to be defined in a cookbook'

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_if(node) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb', line 43

def on_if(node)
  chefspec_matcher?(node) do
    add_offense(node, severity: :refactor) do |corrector|
      corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
    end
  end
end