Class: ChefSpec::Berkshelf

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

Instance Method Summary collapse

Constructor Details

#initializeBerkshelf

Returns a new instance of Berkshelf.



16
17
18
# File 'lib/chefspec/berkshelf.rb', line 16

def initialize
  @tmpdir = Dir.mktmpdir
end

Instance Method Details

#setup!Object

Setup and install the necessary dependencies in the temporary directory.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chefspec/berkshelf.rb', line 23

def setup!
  ::Berkshelf.ui.mute do
    if ::Berkshelf::Berksfile.method_defined?(:vendor)
      FileUtils.rm_rf(@tmpdir) # Berkshelf 3.0 requires the directory to not exist
      ::Berkshelf::Berksfile.from_file('Berksfile').vendor(@tmpdir)
    else
      ::Berkshelf::Berksfile.from_file('Berksfile').install(path: @tmpdir)
    end
  end

  ::RSpec.configure { |config| config.cookbook_path = @tmpdir }
end

#teardown!Object

Destroy the installed Berkshelf at the temporary directory.



39
40
41
# File 'lib/chefspec/berkshelf.rb', line 39

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