spec/integration/integration_helper.rb in braid-1.0.22 vs spec/integration/integration_helper.rb in braid-1.1.0
- 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')
+# 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
+
def with_editor_message(message = 'Make some changes')
File.write(EDITOR_CMD, <<CMD)
#!/usr/bin/env ruby
File.open(ARGV[0], 'w') { |file| file.write(#{message.inspect}) }
CMD
@@ -29,12 +35,12 @@
Braid::Operations::with_modified_environment({'GIT_EDITOR' => EDITOR_CMD}) do
yield
end
end
-def assert_no_diff(file1, file2)
- run_command("diff -U 3 #{file1} #{file2}")
+def assert_no_diff(file1, file2, extra_flags = '')
+ run_command("diff -U 3 #{extra_flags} #{file1} #{file2}")
end
def assert_commit_attribute(format_key, value, commit_index = 0)
output = run_command("git log --pretty=format:#{format_key}").split("\n")
regex = value.is_a?(Regexp) ? value : /^#{value}$/
@@ -52,26 +58,37 @@
def assert_commit_email(value, commit_index = 0)
assert_commit_attribute('%ae', value, commit_index)
end
def in_dir(dir = TMP_PATH)
+ orig_wd = Dir.pwd
Dir.chdir(dir)
- yield
+ begin
+ yield
+ ensure
+ Dir.chdir(orig_wd)
+ end
end
# Note: Do not use single quotes to quote spaces in arguments. They do not work
# on Windows.
def run_command(command)
output = `#{command}`
raise "Error executing command: #{command}\nOutput: #{output}" unless $?.success?
output
end
+def run_command_expect_failure(command)
+ output = `#{command}`
+ raise "Expected command to fail but it succeeded: #{command}\nOutput: #{output}" if $?.success?
+ output
+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)
+ 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
@@ -81,10 +98,11 @@
in_dir(git_repo) do
run_command('git init')
run_command("git config --local user.email \"#{email}\"")
run_command("git config --local user.name \"#{name}\"")
- run_command('git add *')
+ run_command('git config --local commit.gpgsign false')
+ run_command('git add .')
run_command("git commit -m \"initial commit of #{fixture_name}\"")
end
git_repo
end