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: I36b60ea96e5a2d53f58094679bbd0f65b73c2b9f
This commit is contained in:
Takashi Kajinami
2023-01-30 13:30:47 +09:00
parent 6d2eeafde1
commit 7e852c8e85
4 changed files with 15 additions and 14 deletions

View File

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

View File

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

View File

@@ -44,14 +44,14 @@ describe provider_class do
describe '#create' do describe '#create' do
context 'with defaults' do context 'with defaults' do
it 'creates a type' do it 'creates a type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'create', '--format', 'shell', .with('share type', 'create', '--format', 'shell',
['test_type', 'False', '--public', 'True', ['test_type', 'False', '--public', 'True',
'--snapshot-support', 'False', '--snapshot-support', 'False',
'--create-share-from-snapshot-support', 'False', '--create-share-from-snapshot-support', 'False',
'--revert-to-snapshot-support', 'False', '--revert-to-snapshot-support', 'False',
'--mount-snapshot-support', 'False']) '--mount-snapshot-support', 'False'])
.returns('id="90e19aff-1b35-4d60-9ee3-383c530275ab" .and_return('id="90e19aff-1b35-4d60-9ee3-383c530275ab"
name="test_type" name="test_type"
visibility="public" visibility="public"
required_extra_specs="{\'driver_handles_share_servers\': \'False\'}" required_extra_specs="{\'driver_handles_share_servers\': \'False\'}"
@@ -66,9 +66,9 @@ description="None"
describe '#instances' do describe '#instances' do
it 'finds types' do it 'finds types' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'list', '--quiet', '--format', 'csv', []) .with('share type', 'list', '--quiet', '--format', 'csv', [])
.returns('"ID","Name","Visibility","Is Default","Required Extra Specs","Optional Extra Specs","Description" .and_return('"ID","Name","Visibility","Is Default","Required Extra Specs","Optional Extra Specs","Description"
"90e19aff-1b35-4d60-9ee3-383c530275ab","type0","public","False","{\'driver_handles_share_servers\': \'True\'}","{\'snapshot_support\': \'True\'}","" "90e19aff-1b35-4d60-9ee3-383c530275ab","type0","public","False","{\'driver_handles_share_servers\': \'True\'}","{\'snapshot_support\': \'True\'}",""
"90e19aff-1b35-4d60-9ee3-383c530275ab","type1","private","False","{\'driver_handles_share_servers\': \'False\'}","{}","" "90e19aff-1b35-4d60-9ee3-383c530275ab","type1","private","False","{\'driver_handles_share_servers\': \'False\'}","{}",""
') ')
@@ -96,12 +96,12 @@ description="None"
describe '#flush' do describe '#flush' do
context '.is_public' do context '.is_public' do
it 'updates type' do it 'updates type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'set', ['test_type', '--public', 'False']) .with('share type', 'set', ['test_type', '--public', 'False'])
provider.is_public = false provider.is_public = false
provider.flush provider.flush
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'set', ['test_type', '--public', 'True']) .with('share type', 'set', ['test_type', '--public', 'True'])
provider.is_public = true provider.is_public = true
provider.flush provider.flush
@@ -110,12 +110,12 @@ description="None"
context '.snapshot_support' do context '.snapshot_support' do
it 'updates type' do it 'updates type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'set', ['test_type', '--snapshot-support', 'False']) .with('share type', 'set', ['test_type', '--snapshot-support', 'False'])
provider.snapshot_support = false provider.snapshot_support = false
provider.flush provider.flush
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'set', ['test_type', '--snapshot-support', 'True']) .with('share type', 'set', ['test_type', '--snapshot-support', 'True'])
provider.snapshot_support = true provider.snapshot_support = true
provider.flush provider.flush
@@ -125,7 +125,7 @@ description="None"
describe '#destroy' do describe '#destroy' do
it 'destroys a type' do it 'destroys a type' do
provider_class.expects(:openstack) expect(provider_class).to receive(:openstack)
.with('share type', 'delete', 'test_type') .with('share type', 'delete', 'test_type')
provider.destroy provider.destroy
expect(provider.exists?).to be_falsey expect(provider.exists?).to be_falsey

View File

@@ -4,7 +4,6 @@ require 'puppet/type/manila_api_paste_ini'
describe 'Puppet::Type.type(:manila_api_paste_ini)' do describe 'Puppet::Type.type(:manila_api_paste_ini)' do
before :each do before :each do
Puppet::Type.rmtype(:manila_api_paste_ini) Puppet::Type.rmtype(:manila_api_paste_ini)
Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
@manila_api_paste_ini = Puppet::Type.type(:manila_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar') @manila_api_paste_ini = Puppet::Type.type(:manila_api_paste_ini).new(:name => 'DEFAULT/foo', :value => 'bar')
end end