From 4cdc815f8df1a8775a738bd79f62890adeae692a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 16 Mar 2020 12:05:34 -0700 Subject: Revert "CONTROVERSIAL: remove "with a chef repo" shared context." This reverts commit 88c07f9d240d90efe269a776f698c6b7ce47e067. --- .../shared/integration/integration_helper.rb | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'spec/support/shared/integration/integration_helper.rb') diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb index ea1f3accd5..7e52f6a9f8 100644 --- a/spec/support/shared/integration/integration_helper.rb +++ b/spec/support/shared/integration/integration_helper.rb @@ -106,6 +106,37 @@ module IntegrationSupport Dir.chdir(path_to(relative_path)) end + RSpec.shared_context "with a chef repo" do + before :each do + raise "Can only create one directory per test" if @repository_dir + + @repository_dir = Dir.mktmpdir("chef_repo") + Chef::Config.chef_repo_path = @repository_dir + %w{client cookbook data_bag environment node role user}.each do |object_name| + Chef::Config.delete("#{object_name}_path".to_sym) + end + end + + after :each do + if @repository_dir + begin + %w{client cookbook data_bag environment node role user}.each do |object_name| + Chef::Config.delete("#{object_name}_path".to_sym) + end + Chef::Config.delete(:chef_repo_path) + # TODO: "force" actually means "silence all exceptions". this + # silences a weird permissions error on Windows that we should track + # down, but for now there's no reason for it to blow up our CI. + FileUtils.remove_entry_secure(@repository_dir, force = ChefUtils.windows?) + ensure + @repository_dir = nil + end + end + Dir.chdir(@old_cwd) if @old_cwd + end + + end + # Versioned cookbooks RSpec.shared_context "with versioned cookbooks", versioned_cookbooks: true do -- cgit v1.2.1