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
# File 'lib/chefspec/policyfile.rb', line 24

def setup!
  policyfile_path = File.join(Dir.pwd, 'Policyfile.rb')

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

  installer.run

  exporter = ChefDK::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


53
54
55
# File 'lib/chefspec/policyfile.rb', line 53

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