spec/integration/integration_helper.rb in braid-1.1.3 vs spec/integration/integration_helper.rb in braid-1.1.4

- old
+ new

@@ -18,10 +18,16 @@ FileUtils.rm_rf(TMP_PATH) FileUtils.mkdir_p(TMP_PATH) BRAID_BIN = ((defined?(JRUBY_VERSION) || Gem.win_platform?) ? 'ruby ' : '') + File.join(BRAID_PATH, 'bin', 'braid') +# Use a separate, clean cache for each test case (because TMP_PATH is deleted +# and recreated for each test case). We don't want to mess with the user's real +# cache, and this ensures that previous cache contents can't affect the behavior +# of the tests. +ENV['BRAID_LOCAL_CACHE_DIR'] = File.join(TMP_PATH, 'braid-cache') + # Must run in a git repository, though we expect the setting to be the same for # most repositories on a given OS. def filemode_enabled run_command('git config core.filemode').strip == 'true' end @@ -81,23 +87,34 @@ output = `#{command}` raise "Expected command to fail but it succeeded: #{command}\nOutput: #{output}" if $?.success? output end +# Rough equivalent of git.require_version within Braid, but without pulling in a +# bunch of dependencies from Braid::Operations. This small amount of code +# duplication seems like a lesser evil than sorting out all the dependencies. +def git_require_version(required) + actual = run_command('git --version').sub(/^.* version/, '').strip + Gem::Version.new(actual) >= Gem::Version.new(required) +end + def update_dir_from_fixture(dir, fixture = dir) to_dir = File.join(TMP_PATH, dir) FileUtils.mkdir_p(to_dir) - FileUtils.cp_r(File.join(FIXTURE_PATH, fixture) + '/.', to_dir, {preserve: true}) + FileUtils.cp_r(File.join(FIXTURE_PATH, fixture) + '/.', to_dir, preserve: true) end def create_git_repo_from_fixture(fixture_name, options = {}) directory = options[:directory] || fixture_name name = options[:name] || DEFAULT_NAME email = options[:email] || DEFAULT_EMAIL git_repo = File.join(TMP_PATH, directory) update_dir_from_fixture(directory, fixture_name) in_dir(git_repo) do + # Avoid a warning emitted by because we use the old default default branch name + run_command('git config --global init.defaultBranch master') + run_command('git init') run_command("git config --local user.email \"#{email}\"") run_command("git config --local user.name \"#{name}\"") run_command('git config --local commit.gpgsign false') run_command('git add .')