Class: ChefSpec::Policyfile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/chefspec/policyfile.rb

Instance Method Summary collapse

Constructor Details

#initializePolicyfile

Returns a new instance of Policyfile.


17
18
19
# File 'lib/chefspec/policyfile.rb', line 17

def initialize
  @tmpdir = Dir.mktmpdir
end

Instance Method Details

#setup!Object

Setup and install the necessary dependencies in the temporary directory


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chefspec/policyfile.rb', line 24

def setup!
  policyfile_path = RSpec.configuration.policyfile_path
  if policyfile_path.nil?
    policyfile_path = File.join(Dir.pwd, 'Policyfile.rb')
  end

  installer = ChefCLI::PolicyfileServices::Install.new(
    policyfile: policyfile_path,
    ui: ChefCLI::UI.null
  )

  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!Object

Remove the temporary directory


56
57
58
# File 'lib/chefspec/policyfile.rb', line 56

def teardown!
  FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir)
end