X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Fspec%2Ffunctions%2Fdeprecation_spec.rb;h=50203c9b0354879d9f4377d2b188aa009d3bae74;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=bde4e89cc374ed26274699b49e28603e298a821a;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/spec/functions/deprecation_spec.rb b/3rdparty/modules/stdlib/spec/functions/deprecation_spec.rb index bde4e89cc..50203c9b0 100644 --- a/3rdparty/modules/stdlib/spec/functions/deprecation_spec.rb +++ b/3rdparty/modules/stdlib/spec/functions/deprecation_spec.rb @@ -2,58 +2,71 @@ require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 describe 'deprecation' do - before(:each) { + before(:each) do # this is to reset the strict variable to default Puppet.settings[:strict] = :warning - } + end it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(ArgumentError) } + it { is_expected.to run.with_params.and_raise_error(ArgumentError) } - it 'should display a single warning' do - Puppet.expects(:warning).with(includes('heelo')) + it 'displays a single warning' do + if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 && Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') < 0 + expect(Puppet).to receive(:deprecation_warning).with('heelo at :', 'key') + expect(Puppet).to receive(:deprecation_warning).with("Modifying 'autosign' as a setting is deprecated.") + else + expect(Puppet).to receive(:warning).with(include('heelo')).once + end is_expected.to run.with_params('key', 'heelo') end - it 'should display a single warning, despite multiple calls' do - Puppet.expects(:warning).with(includes('heelo')).once - is_expected.to run.with_params('key', 'heelo') - is_expected.to run.with_params('key', 'heelo') + it 'displays a single warning, despite multiple calls' do + if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 && Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') < 0 + expect(Puppet).to receive(:deprecation_warning).with('heelo at :', 'key').twice + expect(Puppet).to receive(:deprecation_warning).with("Modifying 'autosign' as a setting is deprecated.") + else + expect(Puppet).to receive(:warning).with(include('heelo')).once + end + (0..1).each do |_i| + is_expected.to run.with_params('key', 'heelo') + end end - it 'should fail twice with message, with multiple calls. when strict= :error' do + it 'fails twice with message, with multiple calls. when strict= :error' do Puppet.settings[:strict] = :error - Puppet.expects(:warning).with(includes('heelo')).never - is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/) - is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/) + expect(Puppet).to receive(:warning).with(include('heelo')).never + (0..1).each do |_i| + is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, %r{deprecation. key. heelo}) + end end - it 'should display nothing, despite multiple calls. strict= :off' do + it 'displays nothing, despite multiple calls. strict= :off' do Puppet.settings[:strict] = :off - Puppet.expects(:warning).with(includes('heelo')).never - is_expected.to run.with_params('key', 'heelo') - is_expected.to run.with_params('key', 'heelo') + expect(Puppet).to receive(:warning).with(include('heelo')).never + (0..1).each do |_i| + is_expected.to run.with_params('key', 'heelo') + end end - after(:all) { + after(:each) do # this is to reset the strict variable to default Puppet.settings[:strict] = :warning - } + end end elsif Puppet.version.to_f < 4.0 # Puppet version < 4 will use these tests. describe 'deprecation' do - after(:all) do + after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end - before(:all) do - ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + before(:each) do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' end it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it 'should display a single warning' do - scope.expects(:warning).with(includes('heelo')) + it 'displays a single warning' do + expect(scope).to receive(:warning).with(include('heelo')) is_expected.to run.with_params('key', 'heelo') end end