Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_legacy_spec.rb
1 require 'spec_helper'
2
3 if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0
4   describe 'validate_legacy' do
5     it { is_expected.not_to eq(nil) }
6     it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
7
8     describe 'when passing the type assertion and passing the previous validation' do
9       it 'passes without notice' do
10         expect(scope).to receive(:function_validate_foo).with([5]).once
11         expect(Puppet).to receive(:notice).never
12         is_expected.to run.with_params('Integer', 'validate_foo', 5)
13       end
14     end
15
16     describe 'when passing the type assertion and failing the previous validation' do
17       it 'passes with a notice about newly accepted value' do
18         expect(scope).to receive(:function_validate_foo).with([5]).and_raise(Puppet::ParseError, 'foo').once
19         expect(Puppet).to receive(:notice).with(include('Accepting previously invalid value for target type'))
20         is_expected.to run.with_params('Integer', 'validate_foo', 5)
21       end
22     end
23
24     describe 'when failing the type assertion and passing the previous validation' do
25       it 'passes with a deprecation message' do
26         expect(scope).to receive(:function_validate_foo).with(['5']).once
27         expect(subject.func).to receive(:call_function).with('deprecation', 'validate_legacy', include('Integer')).once
28         is_expected.to run.with_params('Integer', 'validate_foo', '5')
29       end
30     end
31
32     describe 'when failing the type assertion and failing the previous validation' do
33       it 'fails with a helpful message' do
34         expect(scope).to receive(:function_validate_foo).with(['5']).and_raise(Puppet::ParseError, 'foo').once
35         expect(subject.func).to receive(:call_function).with('fail', include('Integer')).once
36         is_expected.to run.with_params('Integer', 'validate_foo', '5')
37       end
38     end
39
40     describe 'when passing in undef' do
41       it 'works' do
42         expect(scope).to receive(:function_validate_foo).with([:undef]).once
43         expect(Puppet).to receive(:notice).never
44         is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
45       end
46     end
47
48     describe 'when passing in multiple arguments' do
49       it 'passes with a deprecation message' do
50         expect(scope).to receive(:function_validate_foo).with([:undef, 1, 'foo']).once
51         expect(Puppet).to receive(:notice).never
52         is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
53       end
54     end
55   end
56 end