class Spoom::TestHelpers::Project

A simple project abstraction for testing purposes

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 22
def initialize(path)
  @path = path
  FileUtils.rm_rf(@path)
  FileUtils.mkdir_p(@path)
end

Public Instance Methods

bundle_exec(cmd, *args) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 90
def bundle_exec(cmd, *args)
  opts = {}
  opts[:chdir] = path
  out, err, status = Open3.capture3(["bundle", "exec", cmd, *args].join(' '), opts)
  [out, err, status.success?]
end
bundle_install() click to toggle source
# File lib/spoom/test_helpers/project.rb, line 81
def bundle_install
  opts = {}
  opts[:chdir] = path
  out, err, status = Open3.capture3("bundle", "install", opts)
  [out, err, status.success?]
end
commit(message = "message", date: Time.now.utc) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 74
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
create_and_checkout_branch(name) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 104
def create_and_checkout_branch(name)
  Spoom::Git.exec("git checkout -b #{name}", path: path)
end
current_branch() click to toggle source
# File lib/spoom/test_helpers/project.rb, line 109
def current_branch
  Spoom::Git.current_branch(path: path)
end
destroy() click to toggle source
# File lib/spoom/test_helpers/project.rb, line 99
def destroy
  FileUtils.rm_rf(path)
end
files() click to toggle source
# File lib/spoom/test_helpers/project.rb, line 58
def files
  Dir.glob("#{@path}/**/*").sort
end
gemfile(content) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 32
def gemfile(content)
  write("Gemfile", content)
end
git_init() click to toggle source
# File lib/spoom/test_helpers/project.rb, line 66
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
remove(rel_path) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 52
def remove(rel_path)
  FileUtils.rm_rf(absolute_path(rel_path))
end
sorbet_config(content) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 38
def sorbet_config(content)
  write("sorbet/config", content)
end
write(rel_path, content = "") click to toggle source
# File lib/spoom/test_helpers/project.rb, line 44
def write(rel_path, content = "")
  path = absolute_path(rel_path)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, content)
end

Private Instance Methods

absolute_path(rel_path) click to toggle source
# File lib/spoom/test_helpers/project.rb, line 117
def absolute_path(rel_path)
  (Pathname.new(path) / rel_path).to_s
end