Permalink
Browse files

Add a test helper to setup and teardown tmp git repos easily.

  • Loading branch information...
1 parent 4468700 commit 0350689c4b93f802ee078d284c64568df982969f @queso queso committed Feb 19, 2011
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/helper.rb
View
32 test/helper.rb
@@ -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.