Class: ChefSpec::Berkshelf
- Inherits:
-
Object
- Object
- ChefSpec::Berkshelf
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/chefspec/berkshelf.rb
Instance Method Summary collapse
-
#initialize ⇒ Berkshelf
constructor
A new instance of Berkshelf.
-
#setup! ⇒ Object
Setup and install the necessary dependencies in the temporary directory.
-
#teardown! ⇒ Object
Destroy the installed Berkshelf at the temporary directory.
Constructor Details
#initialize ⇒ Berkshelf
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chefspec/berkshelf.rb', line 23 def setup! # Get the list of Berkshelf options opts = RSpec.configuration. unless opts.is_a?(Hash) raise InvalidBerkshelfOptions(value: opts.inspect) end berksfile = ::Berkshelf::Berksfile.(opts) # Grab a handle to tmpdir, since Berkshelf 2 modifies it a bit tmpdir = File.join(@tmpdir, "cookbooks") ::Berkshelf.ui.mute do if ::Berkshelf::Berksfile.method_defined?(:vendor) # Berkshelf 3.0 requires the directory to not exist FileUtils.rm_rf(tmpdir) berksfile.vendor(tmpdir) else berksfile.install(path: tmpdir) end end filter = Coverage::BerkshelfFilter.new(berksfile) Coverage.add_filter(filter) ::RSpec.configure { |config| config.cookbook_path = tmpdir } end |
#teardown! ⇒ Object
Destroy the installed Berkshelf at the temporary directory.
54 55 56 |
# File 'lib/chefspec/berkshelf.rb', line 54 def teardown! FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir) end |