Skip to content

Commit

Permalink
Add a test helper to setup and teardown tmp git repos easily.
Browse files Browse the repository at this point in the history
  • Loading branch information
queso committed Apr 19, 2011
1 parent 4468700 commit 0350689
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/helper.rb
Expand Up @@ -10,5 +10,37 @@
CIJoe::Server.set :project_path, "."
CIJoe::Server.set :environment, "test"

TMP_DIR = '/tmp/cijoe_test'

def tmp_dir
TMP_DIR
end

def setup_git_info(options = {})
@tmp_dirs ||= []
@tmp_dirs += [options[:tmp_dir]]
create_tmpdir!(options[:tmp_dir])
dir = options[:tmp_dir] || tmp_dir
`cd #{dir} && git init`
options[:config].each do |key, value|
`cd #{dir} && git config --add #{key} "#{value}"`
end
end

def teardown_git_info
remove_tmpdir!
@tmp_dirs.each do |dir|
remove_tmpdir!(dir)
end
end

def remove_tmpdir!(passed_dir = nil)
FileUtils.rm_rf(passed_dir || tmp_dir)
end

def create_tmpdir!(passed_dir = nil)
FileUtils.mkdir_p(passed_dir || tmp_dir)
end

class Test::Unit::TestCase
end

0 comments on commit 0350689

Please sign in to comment.