Skip to content

Commit

Permalink
Merge pull request #592 from rodjek/pdk-1187
Browse files Browse the repository at this point in the history
(PDK-1187) Don't override bundler path on gem installs
  • Loading branch information
bmjen authored Nov 13, 2018
2 parents aca4155 + 66137ad commit 674f2c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
6 changes: 0 additions & 6 deletions lib/pdk/util/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def installed?(gem_overrides = {})
PDK.logger.debug(_('Checking for missing Gemfile dependencies.'))

argv = ['check', "--gemfile=#{gemfile}", '--dry-run']
argv << "--path=#{bundle_cachedir}" unless PDK::Util.package_install?

cmd = bundle_command(*argv).tap do |c|
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
Expand Down Expand Up @@ -192,7 +191,6 @@ def update_lock!(options = {})
def install!(gem_overrides = {})
argv = ['install', "--gemfile=#{gemfile}"]
argv << '-j4' unless Gem.win_platform? && Gem::Version.new(PDK::Util::RubyVersion.active_ruby_version) < Gem::Version.new('2.3.5')
argv << "--path=#{bundle_cachedir}" unless PDK::Util.package_install?

cmd = bundle_command(*argv).tap do |c|
c.add_spinner(_('Installing missing Gemfile dependencies.'))
Expand Down Expand Up @@ -249,10 +247,6 @@ def bundle_command(*args)
c.context = :module
end
end

def bundle_cachedir
@bundle_cachedir ||= PDK::Util.package_install? ? PDK::Util.package_cachedir : File.join(PDK::Util.cachedir)
end
end
end
end
Expand Down
15 changes: 6 additions & 9 deletions spec/unit/pdk/util/bundler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,10 @@ def bundle_regex
include_context 'not packaged install'

let(:instance) { described_class.new }
let(:bundle_cachedir) { '/bundle_cache' }

before(:each) do
# Doesn't matter where this is since all the execs get mocked.
allow(PDK::Util).to receive(:module_root).and_return('/')

allow(PDK::Util).to receive(:cachedir).and_return(bundle_cachedir)
end

describe '#gemfile' do
Expand Down Expand Up @@ -355,20 +352,20 @@ def bundle_regex
end

it 'invokes `bundle check`' do
expect_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run', "--path=#{bundle_cachedir}"], exit_code: 0)
expect_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run'], exit_code: 0)

instance.installed?
end

it 'returns true if `bundle check` exits zero' do
allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run', "--path=#{bundle_cachedir}"], exit_code: 0)
allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run'], exit_code: 0)

expect(instance.installed?).to be true
end

context 'when `bundle check` exits non-zero' do
before(:each) do
allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run', "--path=#{bundle_cachedir}"], exit_code: 1, stderr: 'this is an error message')
allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run'], exit_code: 1, stderr: 'this is an error message')
end

it 'returns false' do
Expand Down Expand Up @@ -396,7 +393,7 @@ def bundle_regex
let(:overrides) { { puppet: '1.2.3' } }

it 'updates env before invoking `bundle check`' do
cmd_double = allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run', "--path=#{bundle_cachedir}"], exit_code: 0)
cmd_double = allow_command([bundle_regex, 'check', "--gemfile=#{gemfile}", '--dry-run'], exit_code: 0)

expect(cmd_double).to receive(:update_environment).with(hash_including('PUPPET_GEM_VERSION' => '1.2.3'))

Expand Down Expand Up @@ -559,7 +556,7 @@ def bundle_regex

describe '#install!' do
let(:gemfile) { '/Gemfile' }
let(:expected_bundle_install) { [bundle_regex, 'install', "--gemfile=#{gemfile}", '-j4', "--path=#{bundle_cachedir}"] }
let(:expected_bundle_install) { [bundle_regex, 'install', "--gemfile=#{gemfile}", '-j4'] }

before(:each) do
allow(instance).to receive(:gemfile).and_return(gemfile)
Expand Down Expand Up @@ -615,7 +612,7 @@ def bundle_regex
end

context 'on Windows running older Ruby' do
let(:expected_bundle_install) { [bundle_regex, 'install', "--gemfile=#{gemfile}", "--path=#{bundle_cachedir}"] }
let(:expected_bundle_install) { [bundle_regex, 'install', "--gemfile=#{gemfile}"] }

before(:each) do
allow(Gem).to receive(:win_platform?).and_return(true)
Expand Down

0 comments on commit 674f2c7

Please sign in to comment.