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) }
8 describe 'when passing the type assertion and passing the previous validation' do
10 scope.expects(:function_validate_foo).with([5]).once
11 Puppet.expects(:notice).never
13 it 'passes without notice' do
14 is_expected.to run.with_params('Integer', 'validate_foo', 5)
18 describe 'when passing the type assertion and failing the previous validation' do
20 scope.expects(:function_validate_foo).with([5]).raises(Puppet::ParseError, 'foo').once
21 Puppet.expects(:notice).with(includes('Accepting previously invalid value for target type'))
23 it 'passes with a notice about newly accepted value' do
24 is_expected.to run.with_params('Integer', 'validate_foo', 5)
28 describe 'when failing the type assertion and passing the previous validation' do
30 scope.expects(:function_validate_foo).with(['5']).once
31 subject.func.expects(:call_function).with('deprecation', 'validate_legacy', includes('Integer')).once
33 it 'passes with a deprecation message' do
34 is_expected.to run.with_params('Integer', 'validate_foo', '5')
38 describe 'when failing the type assertion and failing the previous validation' do
40 scope.expects(:function_validate_foo).with(['5']).raises(Puppet::ParseError, 'foo').once
41 subject.func.expects(:call_function).with('fail', includes('Integer')).once
43 it 'fails with a helpful message' do
44 is_expected.to run.with_params('Integer', 'validate_foo', '5')
48 describe 'when passing in undef' do
50 scope.expects(:function_validate_foo).with([:undef]).once
51 Puppet.expects(:notice).never
54 is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
58 describe 'when passing in multiple arguments' do
60 scope.expects(:function_validate_foo).with([:undef, 1, 'foo']).once
61 Puppet.expects(:notice).never
63 it 'passes with a deprecation message' do
64 is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')