diff --git a/lib/poise_ruby/resources/bundle_install.rb b/lib/poise_ruby/resources/bundle_install.rb index e4b39fd..cd69857 100644 --- a/lib/poise_ruby/resources/bundle_install.rb +++ b/lib/poise_ruby/resources/bundle_install.rb @@ -71,8 +71,8 @@ class Resource < Chef::Resource attribute(:retry, kind_of: [String, Integer]) # @!attribute user # User to run bundler as. - # @return [String] - attribute(:user, kind_of: String) + # @return [String, Integery, nil] + attribute(:user, kind_of: [String, Integer, NilClass]) # @!attribute vendor # Enable local vendoring. This maps to the `--path` option in bundler, # but that attribute name is already used. @@ -157,7 +157,7 @@ def gemfile_path # Install the gems in the Gemfile. def run_bundler(command) return converge_by "Run bundle #{command}" if whyrun_mode? - cmd = ruby_shell_out!(bundler_command(command), environment: {'BUNDLE_GEMFILE' => gemfile_path}) + cmd = ruby_shell_out!(bundler_command(command), environment: {'BUNDLE_GEMFILE' => gemfile_path}, user: new_resource.user) # Look for a line like 'Installing $gemname $version' to know if we did anything. if cmd.stdout.include?('Installing') new_resource.updated_by_last_action(true) diff --git a/test/spec/resources/bundle_install_spec.rb b/test/spec/resources/bundle_install_spec.rb index 3173e57..c1ffd2d 100644 --- a/test/spec/resources/bundle_install_spec.rb +++ b/test/spec/resources/bundle_install_spec.rb @@ -40,7 +40,7 @@ end # /describe PoiseRuby::Resources::BundleInstall::Resource describe PoiseRuby::Resources::BundleInstall::Provider do - let(:new_resource) { double('new_resource', parent_ruby: nil, timeout: 900, ruby: '/usr/bin/ruby') } + let(:new_resource) { double('new_resource', parent_ruby: nil, timeout: 900, ruby: '/usr/bin/ruby', user: nil) } let(:provider) { described_class.new(new_resource, nil) } describe '#action_install' do @@ -63,7 +63,7 @@ before do allow(provider).to receive(:bundler_command).and_return(%w{bundle install}) allow(provider).to receive(:gemfile_path).and_return('Gemfile') - expect(provider).to receive(:ruby_shell_out!).with(%w{bundle install}, environment: {'BUNDLE_GEMFILE' => 'Gemfile'}).and_return(double(stdout: bundle_output)) + expect(provider).to receive(:ruby_shell_out!).with(%w{bundle install}, environment: {'BUNDLE_GEMFILE' => 'Gemfile'}, user: nil).and_return(double(stdout: bundle_output)) end context 'with a new gem' do