Sha256: a92b66ceaa3a287b4a890ab83087956e1f2069de107716a1bde353a7483bb22e

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

context = ChefDK::Generator.context
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
recipe_path = File.join(cookbook_dir, 'recipes', "#{context.new_file_basename}.rb")
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(ChefDK::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(ChefDK::Generator::TemplateHelper)
  action :create_if_missing
end

# Recipe
template recipe_path do
  source 'recipe.rb.erb'
  helpers(ChefDK::Generator::TemplateHelper)
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
chef-dk-4.13.3 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.12.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.11.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.10.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.9.7 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.7.73 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-3.13.1 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.6.35 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-3.12.10 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-3.12.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.5.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.4.27 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.3.13 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.2.0 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.1.7 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb
chef-dk-4.0.60 lib/chef-dk/skeletons/code_generator/recipes/recipe.rb