From 200c8f10e7d29ddaa01f74f239c28ab5c104ba4c Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 30 Jan 2023 10:26:36 +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: I843c72def83a79783d68c9bcf1036d9beddb0e5d --- spec/spec_helper.rb | 2 ++ .../puppet/lib/provider/vs_config_ovs_spec.rb | 18 +++++++++--------- .../puppet/lib/provider/vs_ssl_ovs_spec.rb | 18 +++++++++--------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a5c46c3..e90909f8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,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/puppet/lib/provider/vs_config_ovs_spec.rb b/spec/unit/puppet/lib/provider/vs_config_ovs_spec.rb index 6616eab3..8638d7c9 100644 --- a/spec/unit/puppet/lib/provider/vs_config_ovs_spec.rb +++ b/spec/unit/puppet/lib/provider/vs_config_ovs_spec.rb @@ -11,10 +11,10 @@ describe Puppet::Type.type(:vs_config).provider(:ovs) do context "Testing string values" do before :each do - described_class.expects(:vsctl).with( - "list", "Open_vSwitch", ".").returns 'key1 : value1 + expect(described_class).to receive(:vsctl).with( + "list", "Open_vSwitch", ".").and_return('key1 : value1 key2 : value2 -key3 : value3' +key3 : value3') end it "should return three resources" do @@ -43,10 +43,10 @@ key3 : value3' context "Testing array values" do before :each do - described_class.expects(:vsctl).with( - "list", "Open_vSwitch", ".").returns 'key1 : [abc, def, ghi] + expect(described_class).to receive(:vsctl).with( + "list", "Open_vSwitch", ".").and_return('key1 : [abc, def, ghi] key2 : [def, abc, ghi] -key3 : [1001, 399, 240, 1200]' +key3 : [1001, 399, 240, 1200]') end it "should return three resources" do @@ -70,10 +70,10 @@ key3 : [1001, 399, 240, 1200]' context "Testing hash values" do before :each do - described_class.expects(:vsctl).with( - "list", "Open_vSwitch", ".").returns 'key1 : {} + expect(described_class).to receive(:vsctl).with( + "list", "Open_vSwitch", ".").and_return('key1 : {} key2 : {"hash21"="value21"} -key3 : {"hash31"="value31", "hash32"="value32", "hash33"=33}' +key3 : {"hash31"="value31", "hash32"="value32", "hash33"=33}') end it "should return three resources" do diff --git a/spec/unit/puppet/lib/provider/vs_ssl_ovs_spec.rb b/spec/unit/puppet/lib/provider/vs_ssl_ovs_spec.rb index baca1ecf..b51c249b 100644 --- a/spec/unit/puppet/lib/provider/vs_ssl_ovs_spec.rb +++ b/spec/unit/puppet/lib/provider/vs_ssl_ovs_spec.rb @@ -18,27 +18,27 @@ describe Puppet::Type.type(:vs_ssl).provider(:ovs) do context 'when changing cert_file' do it 'should recreate ssl config' do - File.stubs(:file?).returns(true) - provider.expects(:destroy) - provider.expects(:create) + allow(File).to receive(':file?').and_return(true) + expect(provider).to receive(:destroy) + expect(provider).to receive(:create) provider.cert_file = '/tmp/blah.crt' end end context 'when changing key_file' do it 'should recreate ssl config' do - File.stubs(:file?).returns(true) - provider.expects(:destroy) - provider.expects(:create) + allow(File).to receive(':file?').and_return(true) + expect(provider).to receive(:destroy) + expect(provider).to receive(:create) provider.key_file = '/tmp/blah.pem' end end context 'when changing ca_file' do it 'should recreate ssl config' do - File.stubs(:file?).returns(true) - provider.expects(:destroy) - provider.expects(:create) + allow(File).to receive(':file?').and_return(true) + expect(provider).to receive(:destroy) + expect(provider).to receive(:create) provider.ca_file = '/tmp/blah.crt' end end