added tagging
[rubygit.git] / tests / test_helper.rb
blobc55e1f426dac0f3e45606985cfc4fe135aa56495
1 require 'test/unit'
2 require 'fileutils'
3 require File.dirname(__FILE__) + '/../lib/git'
5 class Test::Unit::TestCase
6   
7   def set_file_paths
8     cwd = `pwd`.chomp
9     if File.directory?(File.join(cwd, 'files'))
10       @test_dir = File.join(cwd, 'files')
11     elsif File.directory?(File.join(cwd, '..', 'files'))
12       @test_dir = File.join(cwd, '..', 'files')
13     elsif File.directory?(File.join(cwd, 'tests', 'files'))
14       @test_dir = File.join(cwd, 'tests', 'files')
15     end
16     
17     @wdir = File.expand_path(File.join(@test_dir, 'working'))
18     @wbare = File.expand_path(File.join(@test_dir, 'working.git'))
19     @index = File.expand_path(File.join(@test_dir, 'index'))
20   end
21   
22   def in_temp_dir(remove_after = true)
23     filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s
24     tmp_path = File.join("/tmp/", filename)
25     FileUtils.mkdir(tmp_path)
26     Dir.chdir tmp_path do
27       yield tmp_path
28     end
29     FileUtils.rm_r(tmp_path) if remove_after
30   end
31   
32   
33   def new_file(name, contents)
34     File.open(name, 'w') do |f|
35       f.puts contents
36     end
37   end
39   def append_file(name, contents)
40     File.open(name, 'a') do |f|
41       f.puts contents
42     end
43   end
44   
45 end