1717 end
1818
1919 before do
20- provider . class . stubs ( :command ) . with ( :npm ) . returns '/usr/local/bin/npm'
20+ allow ( provider . class ) . to receive ( :command ) . with ( :npm ) . and_return ( '/usr/local/bin/npm' )
2121 resource . provider = provider
2222 end
2323
@@ -33,27 +33,27 @@ def self.it_should_respond_to(*actions)
3333
3434 describe 'when installing npm packages' do
3535 it 'uses package name by default' do
36- provider . expects ( :npm ) . with ( 'install' , '--global' , 'express' )
36+ expect ( provider ) . to receive ( :npm ) . with ( 'install' , '--global' , 'express' )
3737 provider . install
3838 end
3939
4040 it 'uses the source instead of the package name' do
4141 resource [ :source ] = '/tmp/express.tar.gz'
42- provider . expects ( :npm ) . with ( 'install' , '--global' , '/tmp/express.tar.gz' )
42+ expect ( provider ) . to receive ( :npm ) . with ( 'install' , '--global' , '/tmp/express.tar.gz' )
4343 provider . install
4444 end
4545
4646 it 'passes the install_options to npm' do
4747 resource [ :install_options ] = [ '--verbose' ]
48- provider . expects ( :npm ) . with ( 'install' , '--global' , '--verbose' , 'express' )
48+ expect ( provider ) . to receive ( :npm ) . with ( 'install' , '--global' , '--verbose' , 'express' )
4949 provider . install
5050 end
5151 end
5252
5353 describe 'and install_options is a hash' do
5454 it 'passes the install_options to npm' do
5555 resource [ :install_options ] = [ { '--loglevel' => 'error' } ]
56- provider . expects ( :npm ) . with ( 'install' , '--global' , '--loglevel=error' , 'express' )
56+ expect ( provider ) . to receive ( :npm ) . with ( 'install' , '--global' , '--loglevel=error' , 'express' )
5757 provider . install
5858 end
5959 end
@@ -64,35 +64,35 @@ def self.it_should_respond_to(*actions)
6464 end
6565
6666 it 'returns a list of npm packages installed globally' do
67- provider . class . expects ( :execute ) .
67+ expect ( provider . class ) . to receive ( :execute ) .
6868 with ( [ '/usr/local/bin/npm' , 'list' , '--json' , '--global' ] , anything ) .
69- returns ( Puppet ::Util ::Execution ::ProcessOutput . new ( File . read ( 'spec/fixtures/unit/puppet/provider/package/npm/npm_global' ) , 0 ) )
69+ and_return ( Puppet ::Util ::Execution ::ProcessOutput . new ( File . read ( 'spec/fixtures/unit/puppet/provider/package/npm/npm_global' ) , 0 ) )
7070 expect ( provider . class . instances . map ( &:properties ) . sort_by { |res | res [ :name ] } ) . to eq ( [
7171 { ensure : '2.5.9' , provider : 'npm' , name : 'express' } ,
7272 { ensure : '1.1.15' , provider : 'npm' , name : 'npm' }
7373 ] )
7474 end
7575
7676 it 'logs and continue if the list command has a non-zero exit code' do
77- provider . class . expects ( :execute ) .
77+ expect ( provider . class ) . to receive ( :execute ) .
7878 with ( [ '/usr/local/bin/npm' , 'list' , '--json' , '--global' ] , anything ) .
79- returns ( Puppet ::Util ::Execution ::ProcessOutput . new ( File . read ( 'spec/fixtures/unit/puppet/provider/package/npm/npm_global' ) , 123 ) )
80- Puppet . expects ( :debug ) . with ( regexp_matches ( %r{123} ) )
79+ and_return ( Puppet ::Util ::Execution ::ProcessOutput . new ( File . read ( 'spec/fixtures/unit/puppet/provider/package/npm/npm_global' ) , 123 ) )
80+ expect ( Puppet ) . to receive ( :debug ) . with ( a_string_matching ( %r{123} ) )
8181 expect ( provider . class . instances . map ( &:properties ) ) . not_to eq ( [ ] )
8282 end
8383
8484 it "logs and return no packages if JSON isn't output" do
85- provider . class . expects ( :execute ) .
85+ expect ( provider . class ) . to receive ( :execute ) .
8686 with ( [ '/usr/local/bin/npm' , 'list' , '--json' , '--global' ] , anything ) .
87- returns ( Puppet ::Util ::Execution ::ProcessOutput . new ( 'failure!' , 0 ) )
88- Puppet . expects ( :debug ) . with ( regexp_matches ( %r{npm list.*failure!} ) )
87+ and_return ( Puppet ::Util ::Execution ::ProcessOutput . new ( 'failure!' , 0 ) )
88+ expect ( Puppet ) . to receive ( :debug ) . with ( a_string_matching ( %r{npm list.*failure!} ) )
8989 expect ( provider . class . instances ) . to eq ( [ ] )
9090 end
9191 end
9292
9393 describe '#latest' do
9494 it 'filters npm registry logging' do
95- provider . expects ( :npm ) . with ( 'view' , 'express' , 'version' ) . returns ( "npm http GET https://registry.npmjs.org/express\n npm http 200 https://registry.npmjs.org/express\n 2.0.0" )
95+ expect ( provider ) . to receive ( :npm ) . with ( 'view' , 'express' , 'version' ) . and_return ( "npm http GET https://registry.npmjs.org/express\n npm http 200 https://registry.npmjs.org/express\n 2.0.0" )
9696 expect ( provider . latest ) . to eq ( '2.0.0' )
9797 end
9898 end
0 commit comments