class ChefSpec::Librarian

Public Class Methods

new() click to toggle source
# File lib/chefspec/librarian.rb, line 20
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/librarian.rb, line 27
def setup!
  env = ::Librarian::Chef::Environment.new(project_path: Dir.pwd)
  @originalpath, env.config_db.local["path"] = env.config_db.local["path"], @tmpdir
  ::Librarian::Action::Resolve.new(env).run
  ::Librarian::Action::Install.new(env).run

  ::RSpec.configure { |config| config.cookbook_path = @tmpdir }
end
teardown!() click to toggle source

Remove the temporary directory and restore the librarian-chef cookbook path.

# File lib/chefspec/librarian.rb, line 39
def teardown!
  env = ::Librarian::Chef::Environment.new(project_path: Dir.pwd)
  env.config_db.local["path"] = @originalpath

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