module Cheffish::RSpec::RepositorySupport

Public Instance Methods

cwd(relative_path) click to toggle source
# File lib/cheffish/rspec/repository_support.rb, line 73
def cwd(relative_path)
  @old_cwd = Dir.pwd
  Dir.chdir(path_to(relative_path))
end
directory(relative_path, &block) click to toggle source
# File lib/cheffish/rspec/repository_support.rb, line 38
def directory(relative_path, &block)
  old_parent_path = @parent_path
  @parent_path = path_to(relative_path)
  FileUtils.mkdir_p(@parent_path)
  instance_eval(&block) if block
  @parent_path = old_parent_path
end
file(relative_path, contents) click to toggle source
# File lib/cheffish/rspec/repository_support.rb, line 46
def file(relative_path, contents)
  filename = path_to(relative_path)
  dir = File.dirname(filename)
  FileUtils.mkdir_p(dir) unless dir == "."
  File.open(filename, "w") do |file|
    raw = case contents
          when Hash, Array
            JSON.pretty_generate(contents)
          else
            contents
          end
    file.write(raw)
  end
end
path_to(relative_path) click to toggle source
# File lib/cheffish/rspec/repository_support.rb, line 69
def path_to(relative_path)
  File.expand_path(relative_path, (@parent_path || @repository_dir))
end
when_the_repository(desc, *tags, &block) click to toggle source
# File lib/cheffish/rspec/repository_support.rb, line 4
def when_the_repository(desc, *tags, &block)
  context("when the chef repo #{desc}", *tags) do
    include_context "with a chef repo"
    extend WhenTheRepositoryClassMethods
    module_eval(&block)
  end
end