class Spoom::TestHelpers::Project

A simple project abstraction for testing purposes

def absolute_path(rel_path)

def absolute_path(rel_path)
  (Pathname.new(path) / rel_path).to_s
end

def bundle_exec(cmd, *args)

def bundle_exec(cmd, *args)
  opts = {}
  opts[:chdir] = path
  out, err, status = Open3.capture3(["bundle", "exec", cmd, *args].join(' '), opts)
  [out, err, T.must(status.success?)]
end

def bundle_install

def bundle_install
  opts = {}
  opts[:chdir] = path
  out, err, status = Open3.capture3("bundle", "install", opts)
  [out, err, T.must(status.success?)]
end

def commit(message = "message", date: Time.now.utc)

def commit(message = "message", date: Time.now.utc)
  Spoom::Git.exec("git add --all", path: path)
  Spoom::Git.exec("GIT_COMMITTER_DATE=\"#{date}\" git commit -m '#{message}' --date '#{date}'", path: path)
end

def create_and_checkout_branch(name)

def create_and_checkout_branch(name)
  Spoom::Git.exec("git checkout -b #{name}", path: path)
end

def current_branch

def current_branch
  Spoom::Git.current_branch(path: path)
end

def destroy

def destroy
  FileUtils.rm_rf(path)
end

def files

def files
  Dir.glob("#{@path}/**/*").sort
end

def gemfile(content)

def gemfile(content)
  write("Gemfile", content)
end

def git_init

def git_init
  Spoom::Git.exec("git init -q", path: path)
  Spoom::Git.exec("git config user.name 'spoom-tests'", path: path)
  Spoom::Git.exec("git config user.email 'spoom@shopify.com'", path: path)
end

def initialize(path)

def initialize(path)
  @path = path
  FileUtils.rm_rf(@path)
  FileUtils.mkdir_p(@path)
end

def remove(rel_path)

def remove(rel_path)
  FileUtils.rm_rf(absolute_path(rel_path))
end

def sorbet_config(content)

def sorbet_config(content)
  write("sorbet/config", content)
end

def write(rel_path, content = "")

def write(rel_path, content = "")
  path = absolute_path(rel_path)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, content)
end