From 7e852c8e8522bf3ee7c61d55d44e2ad53344cfc6 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 30 Jan 2023 13:30:47 +0900 Subject: [PATCH] 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] https://github.com/puppetlabs/puppetlabs_spec_helper/commit/493f0cbc1c96a3fa67591f3936430a70af74847f Closes-Bug: #2004135 Change-Id: I36b60ea96e5a2d53f58094679bbd0f65b73c2b9f --- spec/spec_helper.rb | 2 ++ spec/unit/provider/manila_spec.rb | 8 ++++---- .../provider/manila_type/openstack_spec.rb | 18 +++++++++--------- spec/unit/type/manila_api_paste_ini_spec.rb | 1 - 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 33f27e2d..a99919e7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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! } diff --git a/spec/unit/provider/manila_spec.rb b/spec/unit/provider/manila_spec.rb index f199722c..cabde49c 100644 --- a/spec/unit/provider/manila_spec.rb +++ b/spec/unit/provider/manila_spec.rb @@ -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 mock = {} - Puppet::Util::IniConfig::File.expects(:new).returns(mock) - mock.expects(:read).with('/etc/manila/manila.conf') + expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock) + expect(mock).to receive(:read).with('/etc/manila/manila.conf') expect do klass.manila_credentials end.to raise_error(Puppet::Error, /Manila types will not work/) @@ -39,8 +39,8 @@ describe Puppet::Provider::Manila do 'password' => 'password', } } - Puppet::Util::IniConfig::File.expects(:new).returns(mock) - mock.expects(:read).with('/etc/manila/manila.conf') + expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock) + expect(mock).to receive(:read).with('/etc/manila/manila.conf') expect(klass.manila_credentials).to eq(creds_hash) end diff --git a/spec/unit/provider/manila_type/openstack_spec.rb b/spec/unit/provider/manila_type/openstack_spec.rb index 96ae1ed7..9774c8e5 100644 --- a/spec/unit/provider/manila_type/openstack_spec.rb +++ b/spec/unit/provider/manila_type/openstack_spec.rb @@ -44,14 +44,14 @@ describe provider_class do describe '#create' do context 'with defaults' do it 'creates a type' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'create', '--format', 'shell', ['test_type', 'False', '--public', 'True', '--snapshot-support', 'False', '--create-share-from-snapshot-support', 'False', '--revert-to-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" visibility="public" required_extra_specs="{\'driver_handles_share_servers\': \'False\'}" @@ -66,9 +66,9 @@ description="None" describe '#instances' do it 'finds types' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .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","type1","private","False","{\'driver_handles_share_servers\': \'False\'}","{}","" ') @@ -96,12 +96,12 @@ description="None" describe '#flush' do context '.is_public' do it 'updates type' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'set', ['test_type', '--public', 'False']) provider.is_public = false provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'set', ['test_type', '--public', 'True']) provider.is_public = true provider.flush @@ -110,12 +110,12 @@ description="None" context '.snapshot_support' do it 'updates type' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'set', ['test_type', '--snapshot-support', 'False']) provider.snapshot_support = false provider.flush - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'set', ['test_type', '--snapshot-support', 'True']) provider.snapshot_support = true provider.flush @@ -125,7 +125,7 @@ description="None" describe '#destroy' do it 'destroys a type' do - provider_class.expects(:openstack) + expect(provider_class).to receive(:openstack) .with('share type', 'delete', 'test_type') provider.destroy expect(provider.exists?).to be_falsey diff --git a/spec/unit/type/manila_api_paste_ini_spec.rb b/spec/unit/type/manila_api_paste_ini_spec.rb index 7ff021a2..42a7ace6 100644 --- a/spec/unit/type/manila_api_paste_ini_spec.rb +++ b/spec/unit/type/manila_api_paste_ini_spec.rb @@ -4,7 +4,6 @@ require 'puppet/type/manila_api_paste_ini' describe 'Puppet::Type.type(:manila_api_paste_ini)' do before :each do 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') end