Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 0350689c4b93f802ee078d284c64568df982969f 1 parent 4468700
Josh Owens queso authored

Showing 1 changed file with 32 additions and 0 deletions. Show diff stats Hide diff stats

  1. +32 0 test/helper.rb
32 test/helper.rb
@@ -10,5 +10,37 @@
10 10 CIJoe::Server.set :project_path, "."
11 11 CIJoe::Server.set :environment, "test"
12 12
  13 +TMP_DIR = '/tmp/cijoe_test'
  14 +
  15 +def tmp_dir
  16 + TMP_DIR
  17 +end
  18 +
  19 +def setup_git_info(options = {})
  20 + @tmp_dirs ||= []
  21 + @tmp_dirs += [options[:tmp_dir]]
  22 + create_tmpdir!(options[:tmp_dir])
  23 + dir = options[:tmp_dir] || tmp_dir
  24 + `cd #{dir} && git init`
  25 + options[:config].each do |key, value|
  26 + `cd #{dir} && git config --add #{key} "#{value}"`
  27 + end
  28 +end
  29 +
  30 +def teardown_git_info
  31 + remove_tmpdir!
  32 + @tmp_dirs.each do |dir|
  33 + remove_tmpdir!(dir)
  34 + end
  35 +end
  36 +
  37 +def remove_tmpdir!(passed_dir = nil)
  38 + FileUtils.rm_rf(passed_dir || tmp_dir)
  39 +end
  40 +
  41 +def create_tmpdir!(passed_dir = nil)
  42 + FileUtils.mkdir_p(passed_dir || tmp_dir)
  43 +end
  44 +
13 45 class Test::Unit::TestCase
14 46 end

0 comments on commit 0350689

Please sign in to comment.
Something went wrong with that request. Please try again.