class ChefSpec::Policyfile
def initialize
def initialize @tmpdir = Dir.mktmpdir end
def setup!
Setup and install the necessary dependencies in the temporary directory
def setup! policyfile_path = RSpec.configuration.policyfile_path if policyfile_path.nil? policyfile_path = File.join(Dir.pwd, "Policyfile.rb") end Chef::WorkstationConfigLoader.new(nil).load installer = ChefCLI::PolicyfileServices::Install.new( policyfile: policyfile_path, ui: ChefCLI::UI.null, config: Chef::Config ) installer.run exporter = ChefCLI::PolicyfileServices::ExportRepo.new( policyfile: policyfile_path, export_dir: @tmpdir ) FileUtils.rm_rf(@tmpdir) exporter.run ::RSpec.configure do |config| config.cookbook_path = [ File.join(@tmpdir, "cookbooks"), File.join(@tmpdir, "cookbook_artifacts"), ] end end
def teardown!
Remove the temporary directory
def teardown! FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir) end