Sha256: e0f75fbcc9a3892543d307a24f117655fdf5e6cd9b47abf6fd4421c8a3377cf8

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

module TemporaryFiles
  TEMP_DIR = File.expand_path('tmp', File.join(File.dirname(__FILE__), '..'))

  def remove_temp_directory
    if File.exist?(TemporaryFiles::TEMP_DIR)
      FileUtils.rm_r(TemporaryFiles::TEMP_DIR)
    end
  end

  def temp_path(base)
    File.join(TemporaryFiles::TEMP_DIR, base)
  end

  def project_root
    temp_path('mysite.com')
  end

  def project_path(path)
    File.join(project_root, path)
  end

  def in_temporary_project(*args, &block)
    FileUtils.mkdir_p(File.join(project_root, 'config'))
    File.open(File.join(project_root, 'config', 'config.yml'), 'w').close
    Dir.chdir(project_root) { yield }
  ensure
    remove_temp_directory
  end

  def assert_exists_in_project(path)
    assert File.exist?(project_path(path)), "#{path} should exist"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nesta-0.13.0 test/support/temporary_files.rb
nesta-0.12.0 test/support/temporary_files.rb