bde4e89cc374ed26274699b49e28603e298a821a
[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) {
6       # this is to reset the strict variable to default
7       Puppet.settings[:strict] = :warning
8     }
9
10     it { is_expected.not_to eq(nil) }
11     it { is_expected.to run.with_params().and_raise_error(ArgumentError) }
12
13     it 'should display a single warning' do
14       Puppet.expects(:warning).with(includes('heelo'))
15       is_expected.to run.with_params('key', 'heelo')
16     end
17
18     it 'should display a single warning, despite multiple calls' do
19       Puppet.expects(:warning).with(includes('heelo')).once
20       is_expected.to run.with_params('key', 'heelo')
21       is_expected.to run.with_params('key', 'heelo')
22     end
23
24     it 'should fail twice with message, with multiple calls. when strict= :error' do
25       Puppet.settings[:strict] = :error
26       Puppet.expects(:warning).with(includes('heelo')).never
27       is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/)
28       is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/)
29     end
30
31     it 'should display nothing, despite multiple calls. strict= :off' do
32       Puppet.settings[:strict] = :off
33       Puppet.expects(:warning).with(includes('heelo')).never
34       is_expected.to run.with_params('key', 'heelo')
35       is_expected.to run.with_params('key', 'heelo')
36     end
37
38     after(:all) {
39       # this is to reset the strict variable to default
40       Puppet.settings[:strict] = :warning
41     }
42   end
43 elsif Puppet.version.to_f < 4.0
44   # Puppet version < 4 will use these tests.
45   describe 'deprecation' do
46     after(:all) do
47       ENV.delete('STDLIB_LOG_DEPRECATIONS')
48     end
49     before(:all) do
50       ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
51     end
52     it { is_expected.not_to eq(nil) }
53     it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
54
55     it 'should display a single warning' do
56       scope.expects(:warning).with(includes('heelo'))
57       is_expected.to run.with_params('key', 'heelo')
58     end
59   end
60 end