Replace mocha by rspec-mocks

puppetlabs_spec_helper recommends rspec-mocks instead of mocha[1] and
it uses rspec-mocks by default instead of mocha since v 5.0.0[2]

This is the prep work to adapt to that migration.

[1] https://github.com/puppetlabs/puppetlabs_spec_helper/#mock_with
[2] 493f0cbc1c

Closes-Bug: #2004135
Change-Id: I6336a8fbf1a2ca5036740086d9a5ac13a5a28113
This commit is contained in:
Takashi Kajinami 2023-01-30 13:13:16 +09:00
parent fc55f3068f
commit aee89870e6
4 changed files with 24 additions and 22 deletions

View File

@ -13,6 +13,8 @@ RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
c.mock_with :rspec
end
at_exit { RSpec::Puppet::Coverage.report! }

View File

@ -26,7 +26,7 @@ describe provider_class do
describe 'managing template' do
describe '#create' do
it 'creates a template' do
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing cluster template', 'create', ['--name', 'cluster_template_1', '--node-groups', ['group1:1', 'group2:2'], '--autoconfig'])
provider.create
end
@ -34,8 +34,8 @@ describe provider_class do
describe '#destroy' do
it 'destroys a template' do
subject.stubs(:id).returns('19e4d640-e88f-4241-9475-0543c2bc412b')
subject.class.expects(:request)
allow(subject).to receive(:id).and_return('19e4d640-e88f-4241-9475-0543c2bc412b')
expect(subject.class).to receive(:request)
.with('dataprocessing cluster template', 'delete', '19e4d640-e88f-4241-9475-0543c2bc412b')
provider.destroy
end
@ -53,9 +53,9 @@ describe provider_class do
use_autoconfig: "False"
}
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing cluster template', 'show', '33c85b61-e9b3-468a-ab06-ef60091c68b6')
.returns(hash)
.and_return(hash)
hash = {
id: "19e4d640-e88f-4241-9475-0543c2bc412b",
@ -66,9 +66,9 @@ describe provider_class do
use_autoconfig: "False"
}
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing cluster template', 'show', '19e4d640-e88f-4241-9475-0543c2bc412b')
.returns(hash)
.and_return(hash)
list = [
{
@ -85,9 +85,9 @@ describe provider_class do
}
]
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing cluster template', 'list')
.returns(list)
.and_return(list)
instances = provider_class.instances
expect(instances.count).to eq(2)
expect(instances[0].name).to eq('cluster_template_1')

View File

@ -28,7 +28,7 @@ describe provider_class do
describe 'managing template' do
describe '#create' do
it 'creates a template' do
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing node group template', 'create', ['--name', 'node_group_template_1', '--plugin', 'plugin_name', '--plugin-version', 'some_version', '--auto-security-group', '--flavor', 'small', '--processes', ['process1', 'process2']])
provider.create
end
@ -36,8 +36,8 @@ describe provider_class do
describe '#destroy' do
it 'destroys a template' do
subject.stubs(:id).returns('19e4d640-e88f-4241-9475-0543c2bc412b')
subject.class.expects(:request)
allow(subject).to receive(:id).and_return('19e4d640-e88f-4241-9475-0543c2bc412b')
expect(subject.class).to receive(:request)
.with('dataprocessing node group template', 'delete', '19e4d640-e88f-4241-9475-0543c2bc412b')
provider.destroy
end
@ -58,9 +58,9 @@ describe provider_class do
auto_security_group: "True",
}
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing node group template', 'show', '33c85b61-e9b3-468a-ab06-ef60091c68b6')
.returns(hash)
.and_return(hash)
hash = {
flavor_id: "small",
@ -74,9 +74,9 @@ describe provider_class do
auto_security_group: "True",
}
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing node group template', 'show', '19e4d640-e88f-4241-9475-0543c2bc412b')
.returns(hash)
.and_return(hash)
list = [
{
@ -93,9 +93,9 @@ describe provider_class do
}
]
subject.class.expects(:request)
expect(subject.class).to receive(:request)
.with('dataprocessing node group template', 'list')
.returns(list)
.and_return(list)
instances = provider_class.instances
expect(instances.count).to eq(2)
expect(instances[0].name).to eq('node_group_template_1')

View File

@ -15,8 +15,8 @@ describe Puppet::Provider::Sahara do
it 'should fail if no auth params are passed and the glance config file does not have the expected contents' do
mock = {}
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/sahara/sahara.conf')
expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
expect(mock).to receive(:read).with('/etc/sahara/sahara.conf')
expect do
klass.sahara_credentials
end.to raise_error(Puppet::Error, /Can not to authenticate Sahara/)
@ -39,8 +39,8 @@ describe Puppet::Provider::Sahara do
'password' => 'password',
}
}
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/sahara/sahara.conf')
expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
expect(mock).to receive(:read).with('/etc/sahara/sahara.conf')
expect(klass.sahara_credentials).to eq(creds_hash)
end