Skip to content

Commit

Permalink
Merge pull request #319 from wyardley/fix_spec_tests
Browse files Browse the repository at this point in the history
Resolve issues with tests failing
  • Loading branch information
bastelfreak authored Sep 17, 2017
2 parents 5c78267 + 6b7acb5 commit 6daf7fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
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

0 comments on commit 6daf7fb

Please sign in to comment.