Sha256: c94178751f03ce9529042d76b29a3c236f4bdd280b4cf53e5d179828d833a07f

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Code42TemplateTestHelpers
  APP_NAME = "dummy_app"

  def remove_project_directory
    FileUtils.rm_rf(project_path)
  end

  def create_tmp_directory
    FileUtils.mkdir_p(tmp_path)
  end

  def run_code42template(arguments = nil)
    Dir.chdir(tmp_path) do
      Bundler.with_clean_env do
        add_fakes_to_path
        `
          #{code42template_bin} #{APP_NAME} #{arguments}
        `
      end
    end
  end

  def drop_dummy_database
    if File.exist?(project_path)
      Dir.chdir(project_path) do
        Bundler.with_clean_env do
          `rake db:drop`
        end
      end
    end
  end

  def add_fakes_to_path
    ENV["PATH"] = "#{support_bin}:#{ENV['PATH']}"
  end

  def project_path
    @project_path ||= Pathname.new("#{tmp_path}/#{APP_NAME}")
  end

  private

  def tmp_path
    @tmp_path ||= Pathname.new("#{root_path}/tmp")
  end

  def code42template_bin
    File.join(root_path, 'bin', 'code42template')
  end

  def support_bin
    File.join(root_path, "spec", "fakes", "bin")
  end

  def root_path
    Pathname(__dir__).join('..')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
code42template-2.1.0 spec/code42template.rb
code42template-2.0.0 spec/code42template.rb