Sha256: 34ea6dab4ceb174db6915987b0edbcb8b972fb0973cf919bfde077c38f07162b

Contents?: true

Size: 1.74 KB

Versions: 27

Compression:

Stored size: 1.74 KB

Contents

require 'test/unit'
require 'fileutils'
require 'logger'
require File.dirname(__FILE__) + '/../lib/git'

class Test::Unit::TestCase
  
  def set_file_paths
    cwd = `pwd`.chomp
    if File.directory?(File.join(cwd, 'files'))
      @test_dir = File.join(cwd, 'files')
    elsif File.directory?(File.join(cwd, '..', 'files'))
      @test_dir = File.join(cwd, '..', 'files')
    elsif File.directory?(File.join(cwd, 'tests', 'files'))
      @test_dir = File.join(cwd, 'tests', 'files')
    end
    
    @wdir_dot = File.expand_path(File.join(@test_dir, 'working'))
    @wbare = File.expand_path(File.join(@test_dir, 'working.git'))
    @index = File.expand_path(File.join(@test_dir, 'index'))
    
    @wdir = create_temp_repo(@wdir_dot)
  end
  
  def teardown
    if @tmp_path
      #puts "teardown #{@tmp_path}"
      FileUtils.rm_r(@tmp_path)
    end
  end
  
  def create_temp_repo(clone_path)
    filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
    @tmp_path = File.join("/tmp/", filename)
    FileUtils.mkdir_p(@tmp_path)
    FileUtils.cp_r(clone_path, @tmp_path)
    tmp_path = File.join(@tmp_path, 'working')
    Dir.chdir(tmp_path) do
      FileUtils.mv('dot_git', '.git')
    end
    tmp_path
  end
  
  def in_temp_dir(remove_after = true) # :yields: the temporary dir's path
    filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
    tmp_path = File.join("/tmp/", filename)
    FileUtils.mkdir(tmp_path)
    Dir.chdir tmp_path do
      yield tmp_path
    end
    FileUtils.rm_r(tmp_path) if remove_after
  end
  
  
  def new_file(name, contents)
    File.open(name, 'w') do |f|
      f.puts contents
    end
  end

  def append_file(name, contents)
    File.open(name, 'a') do |f|
      f.puts contents
    end
  end
  
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
titanous-git-1.1.0 tests/test_helper.rb
ruby-git-lacravate-0.0.2 tests/test_helper.rb
ruby-git-lacravate-0.0.1 tests/test_helper.rb
redcar-dev-0.12.1dev-java plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-dev-0.12.0dev-java plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.11 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.11.0dev plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.10 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.9.2 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.9.1 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.9.0 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.8.1 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.8 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.7 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.6.1 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.6 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.6.1dev plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.5.1 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.5 plugins/scm_git/vendor/ruby-git/tests/test_helper.rb
redcar-0.5.6dev plugins/scm_git/vendor/ruby-git/tests/test_helper.rb