Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(setup): added support for bundler 2.x and rubygems 3.x
Browse files Browse the repository at this point in the history
Resolves #203
  • Loading branch information
ajgon committed Jan 5, 2019
1 parent 1d4705d commit 7b781bd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions libraries/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require File.join(libdir, 'core_ext')
require File.join(libdir, 'helpers')
require File.join(libdir, 'archive')
require File.join(libdir, 'chef_patches')
Dir[File.join(libdir, 'drivers_base.rb')].each { |f| require f }
Dir[File.join(libdir, 'drivers_dsl_*.rb')].each { |f| require f }
Dir[File.join(libdir, 'drivers_source_base.rb')].each { |f| require f }
Expand Down
12 changes: 12 additions & 0 deletions libraries/chef_patches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class Chef
class Provider
class Package < Chef::Provider
def shell_out_with_timeout!(*command_args)
command_args[0].gsub!(/--no-rdoc|--no-ri/, '--no-document')
shell_out!(*add_timeout_option(command_args))
end
end
end
end
4 changes: 4 additions & 0 deletions recipes/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@
only_if { node['defaults']['webserver']['adapter'] == 'nginx' }
end

bundler2_applicable = Gem::Requirement.new('>= 3.0.0.beta1').satisfied_by?(
Gem::Version.new(Gem::VERSION)
)
gem_package 'bundler' do
action :install
version '~> 1' unless bundler2_applicable
end

if node['platform_family'] == 'debian'
Expand Down
36 changes: 30 additions & 6 deletions spec/unit/recipes/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,38 @@
end

context 'Gems' do
it 'debian bundler' do
expect(chef_run).to install_gem_package(:bundler)
expect(chef_run).to create_link('/usr/local/bin/bundle').with(to: '/usr/bin/bundle')
context 'when rubygems version is < 3' do
before do
stub_const('Gem::VERSION', '2.7.8')
end

it 'debian bundler' do
expect(chef_run).to install_gem_package(:bundler).with(version: '~> 1')
expect(chef_run).to create_link('/usr/local/bin/bundle').with(to: '/usr/bin/bundle')
end

it 'rhel bundler' do
expect(chef_run_rhel).to install_gem_package(:bundler).with(version: '~> 1')
expect(chef_run_rhel).to create_link('/usr/local/bin/bundle').with(to: '/usr/local/bin/bundler')
end
end

it 'rhel bundler' do
expect(chef_run_rhel).to install_gem_package(:bundler)
expect(chef_run_rhel).to create_link('/usr/local/bin/bundle').with(to: '/usr/local/bin/bundler')
context 'when rubygems version is >= 3' do
before do
stub_const('Gem::VERSION', '3.0.2')
end

it 'debian bundler' do
expect(chef_run).to install_gem_package(:bundler)
expect(chef_run).not_to install_gem_package(:bundler).with(version: '~> 1')
expect(chef_run).to create_link('/usr/local/bin/bundle').with(to: '/usr/bin/bundle')
end

it 'rhel bundler' do
expect(chef_run_rhel).to install_gem_package(:bundler)
expect(chef_run_rhel).not_to install_gem_package(:bundler).with(version: '~> 1')
expect(chef_run_rhel).to create_link('/usr/local/bin/bundle').with(to: '/usr/local/bin/bundler')
end
end
end

Expand Down

0 comments on commit 7b781bd

Please sign in to comment.