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

Use bundler original env when running bundle commands. Fixes #173 #174

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions lib/appraisal/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
module Appraisal
# Executes commands with a clean environment
class Command
BUNDLER_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze

attr_reader :command, :env, :gemfile, :original_env
attr_reader :command, :env, :gemfile

def initialize(command, options = {})
@gemfile = options[:gemfile]
@env = options.fetch(:env, {})
@command = command_starting_with_bundle(command)
@original_env = {}
end

def run
with_clean_env { ensure_bundler_is_available }
announce
Bundler.with_original_env do
ensure_bundler_is_available
announce

with_clean_env do
ENV["BUNDLE_GEMFILE"] = gemfile
ENV["APPRAISAL_INITIALIZED"] = "1"
env.each_pair do |key, value|
ENV[key] = value
end
Expand All @@ -31,15 +30,6 @@ def run

private

def with_clean_env
unset_bundler_env_vars
ENV['BUNDLE_GEMFILE'] = gemfile
ENV['APPRAISAL_INITIALIZED'] = '1'
yield
ensure
restore_env
end

def ensure_bundler_is_available
version = Utils.bundler_version
unless system %(gem list --silent -i bundler -v #{version})
Expand All @@ -66,17 +56,6 @@ def announce
end
end

def unset_bundler_env_vars
BUNDLER_ENV_VARS.each do |key|
original_env[key] = ENV[key]
ENV[key] = nil
end
end

def restore_env
original_env.each { |key, value| ENV[key] = value }
end

def command_starts_with_bundle?(original_command)
if original_command.is_a?(Array)
original_command.first =~ /^bundle/
Expand Down