[test] Ensure that cukes do write operations outside of project dir

This commit is contained in:
Mislav Marohnić 2019-10-29 10:57:43 +01:00
Родитель ba47de35c1
Коммит 595856c483
1 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -5,6 +5,13 @@ require 'tmpdir'
system_git = `which git 2>/dev/null`.chomp
bin_dir = File.expand_path('../fakebin', __FILE__)
tmpdir = Dir.mktmpdir('hub_test')
tmp_bin_dir = "#{tmpdir}/bin"
Aruba.configure do |aruba|
aruba.send(:find_option, :root_directory).value = tmpdir
end
hub_dir = Dir.mktmpdir('hub_build')
raise 'hub build failed' unless system("./script/build -o #{hub_dir}/hub")
@ -16,7 +23,7 @@ Before do
# speed up load time by skipping RubyGems
'RUBYOPT' => '--disable-gems',
# put fakebin on the PATH
'PATH' => "#{hub_dir}:#{bin_dir}:#{ENV['PATH']}",
'PATH' => "#{hub_dir}:#{tmp_bin_dir}:#{bin_dir}:#{ENV['PATH']}",
# clear out GIT if it happens to be set
'GIT' => nil,
# exclude this project's git directory from use in testing
@ -25,7 +32,7 @@ Before do
'GIT_PROXY_COMMAND' => 'echo',
# avoids reading from current user's "~/.gitconfig"
'HOME' => expand_path('home'),
'TMPDIR' => expand_path('tmp'),
'TMPDIR' => tmpdir,
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
'XDG_CONFIG_HOME' => nil,
'XDG_CONFIG_DIRS' => nil,
@ -62,7 +69,7 @@ end
After do
@server.stop if defined? @server and @server
FileUtils.rm_f("#{bin_dir}/vim")
FileUtils.rm_f("#{tmp_bin_dir}/vim")
end
After('@cache_clear') do
@ -118,7 +125,8 @@ World Module.new {
end
define_method(:text_editor_script) do |bash_code|
File.open("#{bin_dir}/vim", 'w', 0755) { |exe|
FileUtils.mkdir_p(tmp_bin_dir)
File.open("#{tmp_bin_dir}/vim", 'w', 0755) { |exe|
exe.puts "#!/bin/bash"
exe.puts "set -e"
exe.puts bash_code