Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend::Exec] ensure no Ruby envvars are present when running command. #300

Merged
merged 1 commit into from Nov 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/serverspec/backend/exec.rb
Expand Up @@ -7,7 +7,9 @@ class Exec < Base
def run_command(cmd, opts={})
cmd = build_command(cmd)
cmd = add_pre_command(cmd)
stdout = `#{build_command(cmd)} 2>&1`
stdout = run_with_no_ruby_environment do
`#{build_command(cmd)} 2>&1`
end
# In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
#stdout, stderr, status = Open3.capture3(cmd)

Expand All @@ -20,6 +22,16 @@ def run_command(cmd, opts={})
:exit_status => $?.exitstatus, :exit_signal => nil }
end

def run_with_no_ruby_environment
keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE
RUBYOPT GEM_HOME GEM_PATH GEM_CACHE]

keys.each { |key| ENV["_SERVERSPEC_#{key}"] = ENV[key] ; ENV.delete(key) }
yield
ensure
keys.each { |key| ENV[key] = ENV.delete("_SERVERSPEC_#{key}") }
end

def build_command(cmd)
path = Serverspec.configuration.path || RSpec.configuration.path
if path
Expand Down