Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / deprecation_spec.rb
1 require 'spec_helper'
2
3 if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4   describe 'deprecation' do
5     before(:each) do
6       # this is to reset the strict variable to default
7       Puppet.settings[:strict] = :warning
8     end
9
10     it { is_expected.not_to eq(nil) }
11     it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
12
13     it 'displays a single warning' do
14       if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 && Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') < 0
15         expect(Puppet).to receive(:deprecation_warning).with('heelo at :', 'key')
16         expect(Puppet).to receive(:deprecation_warning).with("Modifying 'autosign' as a setting is deprecated.")
17       else
18         expect(Puppet).to receive(:warning).with(include('heelo')).once
19       end
20       is_expected.to run.with_params('key', 'heelo')
21     end
22
23     it 'displays a single warning, despite multiple calls' do
24       if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 && Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') < 0
25         expect(Puppet).to receive(:deprecation_warning).with('heelo at :', 'key').twice
26         expect(Puppet).to receive(:deprecation_warning).with("Modifying 'autosign' as a setting is deprecated.")
27       else
28         expect(Puppet).to receive(:warning).with(include('heelo')).once
29       end
30       (0..1).each do |_i|
31         is_expected.to run.with_params('key', 'heelo')
32       end
33     end
34
35     it 'fails twice with message, with multiple calls. when strict= :error' do
36       Puppet.settings[:strict] = :error
37       expect(Puppet).to receive(:warning).with(include('heelo')).never
38       (0..1).each do |_i|
39         is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, %r{deprecation. key. heelo})
40       end
41     end
42
43     it 'displays nothing, despite multiple calls. strict= :off' do
44       Puppet.settings[:strict] = :off
45       expect(Puppet).to receive(:warning).with(include('heelo')).never
46       (0..1).each do |_i|
47         is_expected.to run.with_params('key', 'heelo')
48       end
49     end
50
51     after(:each) do
52       # this is to reset the strict variable to default
53       Puppet.settings[:strict] = :warning
54     end
55   end
56 elsif Puppet.version.to_f < 4.0
57   # Puppet version < 4 will use these tests.
58   describe 'deprecation' do
59     after(:each) do
60       ENV.delete('STDLIB_LOG_DEPRECATIONS')
61     end
62     before(:each) do
63       ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
64     end
65     it { is_expected.not_to eq(nil) }
66     it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
67
68     it 'displays a single warning' do
69       expect(scope).to receive(:warning).with(include('heelo'))
70       is_expected.to run.with_params('key', 'heelo')
71     end
72   end
73 end