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

Resolve issues with tests failing #319

Merged
merged 2 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
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
14 changes: 5 additions & 9 deletions lib/puppet/provider/package/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

has_feature :versionable, :install_options

if Puppet::Util::Package.versioncmp(Puppet.version, '3.0') >= 0
has_command(:npm, 'npm') do
is_optional
environment HOME: '/root'
end
else
optional_commands npm: 'npm'
has_command(:npm, 'npm') do
is_optional
environment HOME: '/root'
end

def self.npmlist
Expand Down Expand Up @@ -68,7 +64,7 @@ def install
end

options = %w[--global]
options += install_options if @resource[:install_options]
options += install_options if resource[:install_options]

if resource[:source]
npm('install', *options, resource[:source])
Expand All @@ -82,6 +78,6 @@ def uninstall
end

def install_options
join_options(@resource[:install_options])
join_options(resource[:install_options])
end
end
50 changes: 25 additions & 25 deletions spec/unit/puppet/provider/package/npm_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#!/usr/bin/env rspec
require 'spec_helper'

describe Puppet::Type.type(:package).provider(:npm) do
let :resource do
let(:resource) do
Puppet::Type.type(:package).new(
name: 'express',
ensure: :present
)
end
let :provider do
described_class.new(resource).tap do |provider|
provider.class.stubs(:optional_commands).with(:npm).returns '/usr/local/bin/npm'
provider.class.stubs(:command).with(:npm).returns '/usr/local/bin/npm'
end

let(:provider) do
provider = described_class.new(resource)
provider.resource = resource
provider
end

before do
provider.class.stubs(:command).with(:npm).returns '/usr/local/bin/npm'
resource.provider = provider
end

def self.it_should_respond_to(*actions)
Expand All @@ -31,28 +35,24 @@ def self.it_should_respond_to(*actions)
provider.install
end

describe 'and a source is specified' do
it 'uses the source instead of the package name' do
resource[:source] = '/tmp/express.tar.gz'
provider.expects(:npm).with('install', '--global', '/tmp/express.tar.gz')
provider.install
end
it 'uses the source instead of the package name' do
resource[:source] = '/tmp/express.tar.gz'
provider.expects(:npm).with('install', '--global', '/tmp/express.tar.gz')
provider.install
end

describe 'and install_options is a string' do
it 'passes the install_options to npm' do
resource[:install_options] = ['--verbose']
provider.expects(:npm).with('install', '--global', '--verbose', 'express')
provider.install
end
it 'passes the install_options to npm' do
resource[:install_options] = ['--verbose']
provider.expects(:npm).with('install', '--global', '--verbose', 'express')
provider.install
end
end

describe 'and install_options is a hash' do
it 'passes the install_options to npm' do
resource[:install_options] = [{ '--loglevel' => 'error' }]
provider.expects(:npm).with('install', '--global', '--loglevel=error', 'express')
provider.install
end
describe 'and install_options is a hash' do
it 'passes the install_options to npm' do
resource[:install_options] = [{ '--loglevel' => 'error' }]
provider.expects(:npm).with('install', '--global', '--loglevel=error', 'express')
provider.install
end
end

Expand Down