1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Invoke bundle correctly within feature tests

During the feature tests we create a separate directory with its own
`Gemfile` and use `bundle` and `bundle exec` within that directory.

However if `bundle exec` was used to run the feature tests, then a
bundler environment is already loaded, and so the test Gemfile is never
consulted. Running `bundle` doesn't have the desired effect, because
the child process inherits the bundler environment variables from the
parent process.

Bundler's solution for this problem is the `Bundle.with_clean_env`
method. This ensures that the child process doesn't inherit the parent's
bundler environment.
This commit is contained in:
Matt Brictson 2017-03-19 19:47:01 -07:00
parent 0cf1ba337c
commit dd42150ddb
No known key found for this signature in database
GPG key ID: 2F279EAD1F2ACFAF

View file

@ -44,14 +44,14 @@ module TestApp
end
Dir.chdir(test_app_path) do
`bundle`
run "bundle"
end
end
def install_test_app_with(config)
create_test_app
Dir.chdir(test_app_path) do
`bundle exec cap install STAGES=#{stage}`
run "cap install STAGES=#{stage}"
end
write_local_deploy_file(config)
end
@ -91,14 +91,15 @@ module TestApp
end
def cap(task, subdirectory=nil)
run "bundle exec cap #{stage} #{task}", subdirectory
run "cap #{stage} #{task} --trace", subdirectory
end
def run(command, subdirectory=nil)
output = nil
command = "bundle exec #{command}" unless command =~ /^bundle\b/
dir = subdirectory ? test_app_path.join(subdirectory) : test_app_path
Dir.chdir(dir) do
output = `#{command}`
output = with_clean_bundler_env { `#{command}` }
end
[$CHILD_STATUS.success?, output]
end
@ -187,4 +188,9 @@ module TestApp
def git_wrapper_path
"/tmp/git-ssh-my_app_name-#{stage}-#{current_user}.sh"
end
def with_clean_bundler_env(&block)
return yield unless defined?(Bundler)
Bundler.with_clean_env(&block)
end
end