Sha256: f4e34c4bcf2a2fe46d0872231cff961d73194fe473ffd5dcdd1d5bee42e19d04

Contents?: true

Size: 1.79 KB

Versions: 18

Compression:

Stored size: 1.79 KB

Contents

context = ChefCLI::Generator.context
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
recipe_path = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.rb")
recipe_path_yml = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.yml")
spec_helper_path = File.join(cookbook_dir, 'spec', 'spec_helper.rb')
spec_dir = File.join(cookbook_dir, 'spec', 'unit', 'recipes')
spec_path = File.join(spec_dir, "#{context.new_file_basename}_spec.rb")
inspec_dir = File.join(cookbook_dir, 'test', 'integration', 'default')
inspec_path = File.join(inspec_dir, "#{context.new_file_basename}_test.rb")

if File.directory?(File.join(cookbook_dir, 'test', 'recipes'))
  Chef::Log.deprecation <<~EOH
    It appears that you have InSpec tests located at "test/recipes". This location can
    cause issues with Foodcritic and has been deprecated in favor of "test/integration/default".
    Please move your existing InSpec tests to the newly created "test/integration/default"
    directory, and update the 'inspec_tests' value in your kitchen.yml file(s) to
    point to "test/integration/default".
  EOH
end

# Chefspec
directory spec_dir do
  recursive true
end

cookbook_file spec_helper_path do
  action :create_if_missing
end

template spec_path do
  source 'recipe_spec.rb.erb'
  helpers(ChefCLI::Generator::TemplateHelper)
  action :create_if_missing
end

# InSpec
directory inspec_dir do
  recursive true
end

template inspec_path do
  source 'inspec_default_test.rb.erb'
  helpers(ChefCLI::Generator::TemplateHelper)
  action :create_if_missing
end

# Recipe
if context.yaml
  template recipe_path_yml do
    source 'recipe.yml.erb'
    helpers(ChefCLI::Generator::TemplateHelper)
  end
else
  template recipe_path do
    source 'recipe.rb.erb'
    helpers(ChefCLI::Generator::TemplateHelper)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chef-cli-5.6.16 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.14 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.13 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.12 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.11 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.8 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.1 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.6.0 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.5.6 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.5.5 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.5.4 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.5.0 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.4.2 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.4.1 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.3.1 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.3.0 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.2.0 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb
chef-cli-5.1.0 lib/chef-cli/skeletons/code_generator/recipes/recipe.rb