From 98ef1e0e34c86bcc11e44a6902b74f52d648bb56 Mon Sep 17 00:00:00 2001 From: Gabriel Nagy Date: Thu, 11 Mar 2021 18:15:33 +0200 Subject: (maint) Switch to rspec-mocks --- spec/lib/puppet_spec/files.rb | 1 - spec/shared_behaviours/all_parsedfile_providers.rb | 2 +- spec/spec_helper.rb | 1 + spec/unit/provider/host/parsed_spec.rb | 8 ++++---- spec/unit/type/host_spec.rb | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index fa774ef..6e2ae89 100644 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -9,7 +9,6 @@ module PuppetSpec::Files def self.cleanup until @global_tempfiles.empty? path = @global_tempfiles.pop - Dir.unstub(:entries) FileUtils.rm_rf path, secure: true end end diff --git a/spec/shared_behaviours/all_parsedfile_providers.rb b/spec/shared_behaviours/all_parsedfile_providers.rb index d697a14..1701fe3 100644 --- a/spec/shared_behaviours/all_parsedfile_providers.rb +++ b/spec/shared_behaviours/all_parsedfile_providers.rb @@ -5,7 +5,7 @@ shared_examples_for 'all parsedfile providers' do |provider, *files| files.flatten.each do |file| it "should rewrite #{file} reasonably unchanged" do - provider.stubs(:default_target).returns(file) + allow(provider).to receive(:default_target).and_return(file) provider.prefetch text = provider.to_file(provider.target_records(file)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index feb5720..29615cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,6 +31,7 @@ default_facts.each do |fact, value| end RSpec.configure do |c| + c.mock_with :rspec c.default_facts = default_facts c.before :each do # set to strictest setting for testing diff --git a/spec/unit/provider/host/parsed_spec.rb b/spec/unit/provider/host/parsed_spec.rb index e07c83d..32e8b44 100644 --- a/spec/unit/provider/host/parsed_spec.rb +++ b/spec/unit/provider/host/parsed_spec.rb @@ -29,10 +29,10 @@ describe Puppet::Type.type(:host).provider(:parsed) do end def genhost(host) - provider.stubs(:filetype).returns(Puppet::Util::FileType::FileTypeRam) - File.stubs(:chown) - File.stubs(:chmod) - Puppet::Util::SUIDManager.stubs(:asuser).yields + allow(provider).to receive(:filetype).and_return(Puppet::Util::FileType::FileTypeRam) + allow(File).to receive(:chown) + allow(File).to receive(:chmod) + allow(Puppet::Util::SUIDManager).to receive(:asuser).and_yield host.flush provider.target_object(hostfile).read end diff --git a/spec/unit/type/host_spec.rb b/spec/unit/type/host_spec.rb index 426657a..54d9b75 100644 --- a/spec/unit/type/host_spec.rb +++ b/spec/unit/type/host_spec.rb @@ -4,7 +4,7 @@ FakeHostProvider = Struct.new(:ip, :host_aliases, :comment) describe Puppet::Type.type(:host) do let(:provider) { FakeHostProvider.new } - let(:resource) { stub('resource', resource: nil, provider: provider) } + let(:resource) { instance_double('Puppet::Type::Host', provider: provider) } it 'has :name be its namevar' do expect(described_class.key_attributes).to eq([:name]) @@ -645,7 +645,7 @@ describe Puppet::Type.type(:host) do it 'alsoes use the specified delimiter for joining' do host_aliases = described_class.attrclass(:host_aliases).new(resource: resource, should: ['foo', 'bar']) - host_aliases.stubs(:delimiter).returns "\t" + allow(host_aliases).to receive(:delimiter).and_return "\t" host_aliases.sync expect(provider.host_aliases).to eq("foo\tbar") -- cgit v1.2.3