Skip to content

Commit 1366422

Browse files
authored
Merge pull request #514 from voxpupuli/plumbing/issues/78
refactor: change from mocha to rspec-mocks
2 parents ff990b4 + 4d7df83 commit 1366422

6 files changed

Lines changed: 34 additions & 22 deletions

File tree

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
inherit_from: .rubocop_todo.yml
3+
24
# Managed by modulesync - DO NOT EDIT
35
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/
46

.rubocop_todo.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
3+
# using RuboCop version 1.50.2.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 10
10+
# Configuration parameters: .
11+
# SupportedStyles: have_received, receive
12+
RSpec/MessageSpies:
13+
EnforcedStyle: receive
14+
15+
# Offense count: 4
16+
RSpec/StubbedMock:
17+
Exclude:
18+
- 'spec/unit/puppet/provider/package/npm_spec.rb'

.sync.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
---
2-
spec/spec_helper.rb:
3-
mock_with: ':mocha'
42
spec/spec_helper_acceptance.rb:
53
unmanaged: true
64
.github/workflows/ci.yml:
75
with:
86
beaker_facter: 'nodejs_version:NodeJS:16,18,20,22'
9-
Gemfile:
10-
optional:
11-
':test':
12-
- gem: 'mocha'

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
66
group :test do
77
gem 'voxpupuli-test', '~> 11.0', :require => false
88
gem 'puppet_metadata', '~> 5.0', :require => false
9-
gem 'mocha', :require => false
109
end
1110

1211
group :development do

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
RSpec.configure do |c|
1313
c.facterdb_string_keys = false
14-
c.mock_with :mocha
1514
end
1615

1716
add_mocked_facts!

spec/unit/puppet/provider/package/npm_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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\nnpm http 200 https://registry.npmjs.org/express\n2.0.0")
95+
expect(provider).to receive(:npm).with('view', 'express', 'version').and_return("npm http GET https://registry.npmjs.org/express\nnpm http 200 https://registry.npmjs.org/express\n2.0.0")
9696
expect(provider.latest).to eq('2.0.0')
9797
end
9898
end

0 commit comments

Comments
 (0)