class ChefSpec::Policyfile
Public Class Methods
new()
click to toggle source
# File lib/chefspec/policyfile.rb, line 18 def initialize @tmpdir = Dir.mktmpdir end
Public Instance Methods
setup!()
click to toggle source
Setup and install the necessary dependencies in the temporary directory
# File lib/chefspec/policyfile.rb, line 25 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
teardown!()
click to toggle source
Remove the temporary directory
# File lib/chefspec/policyfile.rb, line 60 def teardown! FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir) end