From 53f5a73d783d5f629b6931c62b6a76caab2f6cbf Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Thu, 22 Mar 2018 11:07:04 +0000 Subject: [PATCH 1/5] Deprecating functions that have been ported to Puppet 5.5.0. --- README.md | 12 ++++++++++++ lib/puppet/parser/functions/empty.rb | 2 ++ lib/puppet/parser/functions/flatten.rb | 2 ++ lib/puppet/parser/functions/join.rb | 2 ++ lib/puppet/parser/functions/keys.rb | 2 ++ lib/puppet/parser/functions/values.rb | 2 ++ spec/acceptance/values_spec.rb | 3 ++- spec/functions/empty_spec.rb | 2 +- spec/functions/flatten_spec.rb | 8 ++++---- spec/functions/join_spec.rb | 6 +++--- spec/functions/keys_spec.rb | 25 ++++++++++++++----------- spec/functions/length_spec.rb | 4 ++-- spec/functions/values_spec.rb | 24 +++++++++++++----------- 13 files changed, 61 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 326de8d63..d7ca315d2 100644 --- a/README.md +++ b/README.md @@ -1163,6 +1163,8 @@ Converts the case of a string or of all strings in an array to lowercase. #### `empty` +**Deprecated. Puppet 5.5.0 has introduced a built in `empty` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Returns `true` if the argument is an array or hash that contains no elements, or an empty string. Returns `false` when the argument is a numerical value. *Type*: rvalue. @@ -1274,6 +1276,8 @@ fact('vmware."VRA.version"') #### `flatten` +**Deprecated. Puppet 5.5.0 has introduced a built in `flatten` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Flattens deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. @@ -1631,6 +1635,8 @@ Returns `true` if the variable passed to this function is a string. #### `join` +**Deprecated. Puppet 5.5.0 has introduced a built in `join` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c". *Type*: rvalue. @@ -1647,12 +1653,16 @@ For example, `join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ")` results in ["a i #### `keys` +**Deprecated. Puppet 5.5.0 has introduced a built in `keys` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Returns the keys of a hash as an array. *Type*: rvalue. #### `length` +**Deprecated. Puppet 5.5.0 has introduced a built in `length` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Returns the length of a given string, array or hash. Replaces the deprecated `size()` function. *Type*: rvalue. @@ -2774,6 +2784,8 @@ validate_x509_rsa_key_pair($cert, $key) #### `values` +**Deprecated. Puppet 5.5.0 has introduced a built in `values` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** + Returns the values of a given hash. For example, given `$hash = {'a'=1, 'b'=2, 'c'=3} values($hash)` returns [1,2,3]. diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index 79c43d0b1..c7d1a14ca 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -7,6 +7,8 @@ module Puppet::Parser::Functions DOC ) do |arguments| + function_deprecation([:empty, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) + raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb index 15970dfa5..1f3bd125e 100644 --- a/lib/puppet/parser/functions/flatten.rb +++ b/lib/puppet/parser/functions/flatten.rb @@ -14,6 +14,8 @@ module Puppet::Parser::Functions DOC ) do |arguments| + function_deprecation([:flatten, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes']) + raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 array = arguments[0] diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index bcb97b70c..20cbb3ce0 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -13,6 +13,8 @@ module Puppet::Parser::Functions DOC ) do |arguments| + function_deprecation([:join, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes']) + # Technically we support two arguments but only first is mandatory ... raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb index 0ecd48f9e..19c6610fc 100644 --- a/lib/puppet/parser/functions/keys.rb +++ b/lib/puppet/parser/functions/keys.rb @@ -7,6 +7,8 @@ module Puppet::Parser::Functions DOC ) do |arguments| + function_deprecation([:keys, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) + raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb index 168da84b6..b3b027f1d 100644 --- a/lib/puppet/parser/functions/values.rb +++ b/lib/puppet/parser/functions/values.rb @@ -20,6 +20,8 @@ module Puppet::Parser::Functions DOC ) do |arguments| + function_deprecation([:values, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) + raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb index 4e5532e5c..9aed79b6d 100644 --- a/spec/acceptance/values_spec.rb +++ b/spec/acceptance/values_spec.rb @@ -23,7 +23,8 @@ notice(inline_template('<%= @output.inspect %>')) DOC it 'handles non-hash arguments' do - expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{Requires hash}) + expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{Requires hash}) if return_puppet_version < '5.5.0' + expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{expects a Hash value}) if return_puppet_version >= '5.5.0' end end end diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index dbe038b34..2db87bdcd 100644 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -2,7 +2,7 @@ describe 'empty' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index ed30e015a..8af999e2c 100644 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -2,10 +2,10 @@ describe 'flatten' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['one']).and_return(['one']) } it { is_expected.to run.with_params([['one']]).and_return(['one']) } diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index a40a7f61c..eeb887a63 100644 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -2,13 +2,13 @@ describe 'join' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' it { pending('Current implementation ignores parameters after the second.') is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) } - it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) } if Puppet.version < '5.5.0' it { is_expected.to run.with_params([]).and_return('') } it { is_expected.to run.with_params([], ':').and_return('') } diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index db864fb6d..4dad10293 100644 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -2,23 +2,26 @@ describe 'keys' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' it { is_expected.to run.with_params({}).and_return([]) } it { is_expected.to run.with_params('key' => 'value').and_return(['key']) } - it 'returns the array of keys' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) - expect(result).to match_array(%w[key1 key2]) - end - it 'runs with UTF8 and double byte characters' do - result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) - expect(result).to match_array(%w[ҝểү キー]) + if Puppet.version < '5.5.0' + it 'returns the array of keys' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) + expect(result).to match_array(%w[key1 key2]) + end + + it 'runs with UTF8 and double byte characters', :if => Puppet.version < '5.5.0' do + result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) + expect(result).to match_array(%w[ҝểү キー]) + end end end diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb index 71845b16a..7bad7b023 100644 --- a/spec/functions/length_spec.rb +++ b/spec/functions/length_spec.rb @@ -4,8 +4,8 @@ it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'length' expects 1 argument, got none}) } it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, %r{'length' expects 1 argument, got 2}) } - it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) } - it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) } + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) } if Puppet.version < '5.5.0' it { is_expected.to run.with_params('1').and_return(1) } it { is_expected.to run.with_params('1.0').and_return(3) } it { is_expected.to run.with_params([]).and_return(0) } diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index b02b0af95..e383989cb 100644 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -2,23 +2,25 @@ describe 'values' do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params({}, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' it { is_expected.to run.with_params({}).and_return([]) } it { is_expected.to run.with_params('key' => 'value').and_return(['value']) } - it 'returns the array of values' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) - expect(result).to match_array(%w[value1 value2 value2]) - end - it 'runs with UTF8 and double byte characters' do - result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) - expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) + if Puppet.version < '5.5.0' + it 'returns the array of values' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) + expect(result).to match_array(%w[value1 value2 value2]) + end + it 'runs with UTF8 and double byte characters' do + result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) + expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) + end end end From a3762385048ba3c90397e540763f38cd6a3c7f0a Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Fri, 23 Mar 2018 14:51:45 +0000 Subject: [PATCH 2/5] Adding deprecation warning for length (Puppet4 function). --- lib/puppet/functions/length.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb index 8cd43e5f4..bacb64215 100644 --- a/lib/puppet/functions/length.rb +++ b/lib/puppet/functions/length.rb @@ -11,4 +11,5 @@ def length(value) end result end + Puppet.deprecation_warning('The length function is deprecated. This function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.') end From 331118f5e12907245fb765b9a2be42e84dcfe034 Mon Sep 17 00:00:00 2001 From: Paula McMaw Date: Fri, 23 Mar 2018 16:40:32 +0000 Subject: [PATCH 3/5] Adding unit tests --- spec/functions/empty_spec.rb | 17 +++++++++++++++++ spec/functions/flatten_spec.rb | 18 ++++++++++++++++++ spec/functions/join_spec.rb | 17 +++++++++++++++++ spec/functions/keys_spec.rb | 17 +++++++++++++++++ spec/functions/values_spec.rb | 17 +++++++++++++++++ 5 files changed, 86 insertions(+) diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index 2db87bdcd..9060b8435 100644 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -19,4 +19,21 @@ it { is_expected.to run.with_params({}).and_return(true) } it { is_expected.to run.with_params('key' => 'value').and_return(false) } + + context 'with deprecation warning' do + after(:each) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'displays a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(0).and_return(false) + end + it 'displays no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(0).and_return(false) + end + end end diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index 8af999e2c..118ea6aa7 100644 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' +# rubocop:disable Style/WordArray, Layout/SpaceAfterComma describe 'flatten' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' @@ -12,4 +13,21 @@ it { is_expected.to run.with_params(%w[a b c d e f g]).and_return(%w[a b c d e f g]) } it { is_expected.to run.with_params([['a', 'b', ['c', %w[d e], 'f', 'g']]]).and_return(%w[a b c d e f g]) } it { is_expected.to run.with_params(['ã', 'β', ['ĉ', %w[đ ẽ ƒ ġ]]]).and_return(%w[ã β ĉ đ ẽ ƒ ġ]) } + + context 'with deprecation warning' do + after(:each) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'displays a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c']) + end + it 'displays no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c']) + end + end end diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index eeb887a63..f1a8e19d5 100644 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -17,4 +17,21 @@ it { is_expected.to run.with_params(%w[one two three]).and_return('onetwothree') } it { is_expected.to run.with_params(%w[one two three], ':').and_return('one:two:three') } it { is_expected.to run.with_params(%w[ōŋể ŧשợ ţђŕẽё], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') } + + context 'with deprecation warning' do + after(:each) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'displays a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params([]).and_return('') + end + it 'displays no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params([]).and_return('') + end + end end diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index 4dad10293..4adab7db6 100644 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -24,4 +24,21 @@ expect(result).to match_array(%w[ҝểү キー]) end end + + context 'with deprecation warning' do + after(:each) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'displays a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params({}).and_return([]) + end + it 'displays no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params({}).and_return([]) + end + end end diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index e383989cb..d6d57d375 100644 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -23,4 +23,21 @@ expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) end end + + context 'with deprecation warning' do + after(:each) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'displays a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('key' => 'value').and_return(['value']) + end + it 'displays no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('key' => 'value').and_return(['value']) + end + end end From 2749a6afa09d404449513b7cafed2c73f1bc09f7 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 26 Mar 2018 15:22:28 -0700 Subject: [PATCH 4/5] Make deprecations more consistent Sometimes the word "deprecated" was all caps, sometimes just capitalized. Sometimes followed by a period, sometimes a colon. Sometimes just the word was bold, sometimes the whole line. Updated to be capitalized, colonized, and only bolding the word. --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d7ca315d2..78ef4eee2 100644 --- a/README.md +++ b/README.md @@ -1059,7 +1059,7 @@ For example: #### `dig` -> DEPRECATED: This function has been replaced with a built-in [`dig`](https://docs.puppet.com/puppet/latest/function.html#dig) function as of Puppet 4.5.0. Use [`dig44()`](#dig44) for backwards compatibility or use the new version. +**Deprecated:** This function has been replaced with a built-in [`dig`](https://docs.puppet.com/puppet/latest/function.html#dig) function as of Puppet 4.5.0. Use [`dig44()`](#dig44) for backwards compatibility or use the new version. Retrieves a value within multiple layers of hashes and arrays via an array of keys containing a path. The function goes through the structure by each path component and tries to return the value at the end of the path. @@ -1518,7 +1518,7 @@ if $baz.is_a(String) { #### `is_absolute_path` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the given path is absolute. @@ -1526,7 +1526,7 @@ Returns `true` if the given path is absolute. #### `is_array` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is an array. @@ -1534,7 +1534,7 @@ Returns `true` if the variable passed to this function is an array. #### `is_bool` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is a Boolean. @@ -1542,7 +1542,7 @@ Returns `true` if the variable passed to this function is a Boolean. #### `is_domain_name` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the string passed to this function is a syntactically correct domain name. @@ -1557,7 +1557,7 @@ Returns true if the string passed to this function is a valid email address. #### `is_float` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is a float. @@ -1565,7 +1565,7 @@ Returns `true` if the variable passed to this function is a float. #### `is_function_available` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Accepts a string as an argument and determines whether the Puppet runtime has access to a function by that name. It returns `true` if the function exists, `false` if not. @@ -1573,7 +1573,7 @@ Accepts a string as an argument and determines whether the Puppet runtime has ac #### `is_hash` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is a hash. @@ -1581,7 +1581,7 @@ Returns `true` if the variable passed to this function is a hash. #### `is_integer` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable returned to this string is an integer. @@ -1589,7 +1589,7 @@ Returns `true` if the variable returned to this string is an integer. #### `is_ip_address` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the string passed to this function is a valid IP address. @@ -1597,7 +1597,7 @@ Returns `true` if the string passed to this function is a valid IP address. #### `is_ipv6_address` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the string passed to this function is a valid IPv6 address. @@ -1605,7 +1605,7 @@ Returns `true` if the string passed to this function is a valid IPv6 address. #### `is_ipv4_address` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the string passed to this function is a valid IPv4 address. @@ -1619,7 +1619,7 @@ Returns `true` if the string passed to this function is a valid MAC address. #### `is_numeric` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is a number. @@ -1627,7 +1627,7 @@ Returns `true` if the variable passed to this function is a number. #### `is_string` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Returns `true` if the variable passed to this function is a string. @@ -2142,7 +2142,7 @@ For example, `{ "key" => "value" }` becomes `"---\nkey: value\n"`. #### `try_get_value` -**DEPRECATED:** replaced by `dig()`. +**Deprecated:** replaced by `dig()`. Retrieves a value within multiple layers of hashes and arrays. @@ -2191,7 +2191,7 @@ $value = try_get_value($data, 'a|b', [], '|') #### `type3x` -**Deprecated**. This function will be removed in a future release. +**Deprecated:** This function will be removed in a future release. Returns a string description of the type of a given value. The type can be a string, array, hash, float, integer, or Boolean. For Puppet 4, use the new type system instead. @@ -2298,7 +2298,7 @@ validate_absolute_path($undefined) #### `validate_array` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that all passed values are array data structures. Terminates catalog compilation if any value fails this check. @@ -2351,7 +2351,7 @@ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers #### `validate_bool` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that all passed values are either `true` or `false`. Terminates catalog compilation if any value fails this check. @@ -2398,7 +2398,7 @@ validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to va #### `validate_domain_name` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validate that all values passed are syntactically correct domain names. Aborts catalog compilation if any value fails this check. @@ -2445,7 +2445,7 @@ validate_email_address($some_array) #### `validate_hash` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that all passed values are hash data structures. Terminates catalog compilation if any value fails this check. @@ -2469,7 +2469,7 @@ validate_hash($undefined) #### `validate_integer` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates an integer or an array of integers. Terminates catalog compilation if any of the checks fail. @@ -2529,7 +2529,7 @@ validate_integer(1, 3, true) #### `validate_ip_address` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that the argument is an IP address, regardless of whether it is an IPv4 or an IPv6 address. It also validates IP address with netmask. @@ -2645,7 +2645,7 @@ Always note such changes in your CHANGELOG and README. #### `validate_numeric` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates a numeric value, or an array or string of numeric values. Terminates catalog compilation if any of the checks fail. @@ -2663,7 +2663,7 @@ For passing and failing usage, see [`validate_integer`](#validate-integer). The #### `validate_re` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Performs simple validation of a string against one or more regular expressions. @@ -2704,7 +2704,7 @@ To force stringification, use quotes: #### `validate_slength` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that a string (or an array of strings) is less than or equal to a specified length @@ -2734,7 +2734,7 @@ validate_slength(["discombobulate","moo"],17,10) #### `validate_string` -**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).** +**Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check. From 67c1c2b286d4a0653bf1944076526c3beaa1599f Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Mon, 26 Mar 2018 15:22:07 -0700 Subject: [PATCH 5/5] Conditionalize specs, make readme deprecations consistent The dig() deprecation message is clear and applies to these functions as well. Also linked to the documentation instead of the release notes. --- README.md | 12 ++++---- lib/puppet/functions/length.rb | 1 - lib/puppet/parser/functions/empty.rb | 2 -- lib/puppet/parser/functions/flatten.rb | 2 -- lib/puppet/parser/functions/join.rb | 2 -- lib/puppet/parser/functions/keys.rb | 2 -- lib/puppet/parser/functions/values.rb | 2 -- spec/acceptance/empty_spec.rb | 2 +- spec/acceptance/flatten_spec.rb | 2 +- spec/acceptance/join_spec.rb | 2 +- spec/acceptance/keys_spec.rb | 2 +- spec/acceptance/values_spec.rb | 5 ++- spec/functions/empty_spec.rb | 21 ++----------- spec/functions/flatten_spec.rb | 28 +++-------------- spec/functions/join_spec.rb | 25 +++------------ spec/functions/keys_spec.rb | 42 +++++++------------------- spec/functions/length_spec.rb | 6 ++-- spec/functions/values_spec.rb | 41 +++++++------------------ 18 files changed, 48 insertions(+), 151 deletions(-) diff --git a/README.md b/README.md index 78ef4eee2..206ba4447 100644 --- a/README.md +++ b/README.md @@ -1163,7 +1163,7 @@ Converts the case of a string or of all strings in an array to lowercase. #### `empty` -**Deprecated. Puppet 5.5.0 has introduced a built in `empty` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`empty`](https://docs.puppet.com/puppet/latest/function.html#empty) function as of Puppet 5.5.0. Returns `true` if the argument is an array or hash that contains no elements, or an empty string. Returns `false` when the argument is a numerical value. @@ -1276,7 +1276,7 @@ fact('vmware."VRA.version"') #### `flatten` -**Deprecated. Puppet 5.5.0 has introduced a built in `flatten` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`flatten`](https://docs.puppet.com/puppet/latest/function.html#flatten) function as of Puppet 5.5.0. Flattens deeply nested arrays and returns a single flat array as a result. @@ -1635,7 +1635,7 @@ Returns `true` if the variable passed to this function is a string. #### `join` -**Deprecated. Puppet 5.5.0 has introduced a built in `join` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`join`](https://docs.puppet.com/puppet/latest/function.html#join) function as of Puppet 5.5.0. Joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c". @@ -1653,7 +1653,7 @@ For example, `join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ")` results in ["a i #### `keys` -**Deprecated. Puppet 5.5.0 has introduced a built in `keys` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`keys`](https://docs.puppet.com/puppet/latest/function.html#keys) function as of Puppet 5.5.0. Returns the keys of a hash as an array. @@ -1661,7 +1661,7 @@ Returns the keys of a hash as an array. #### `length` -**Deprecated. Puppet 5.5.0 has introduced a built in `length` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`length`](https://docs.puppet.com/puppet/latest/function.html#length) function as of Puppet 5.5.0. Returns the length of a given string, array or hash. Replaces the deprecated `size()` function. @@ -2784,7 +2784,7 @@ validate_x509_rsa_key_pair($cert, $key) #### `values` -**Deprecated. Puppet 5.5.0 has introduced a built in `values` function, which will take precedence over the stdlib function. See [Puppet 5.5.0 Release Notes](https://puppet.com/docs/puppet/5.5/release_notes.html#new-features).** +**Deprecated:** This function has been replaced with a built-in [`values`](https://docs.puppet.com/puppet/latest/function.html#values) function as of Puppet 5.5.0. Returns the values of a given hash. diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb index bacb64215..8cd43e5f4 100644 --- a/lib/puppet/functions/length.rb +++ b/lib/puppet/functions/length.rb @@ -11,5 +11,4 @@ def length(value) end result end - Puppet.deprecation_warning('The length function is deprecated. This function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.') end diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index c7d1a14ca..79c43d0b1 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -7,8 +7,6 @@ module Puppet::Parser::Functions DOC ) do |arguments| - function_deprecation([:empty, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) - raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb index 1f3bd125e..15970dfa5 100644 --- a/lib/puppet/parser/functions/flatten.rb +++ b/lib/puppet/parser/functions/flatten.rb @@ -14,8 +14,6 @@ module Puppet::Parser::Functions DOC ) do |arguments| - function_deprecation([:flatten, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes']) - raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 array = arguments[0] diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index 20cbb3ce0..bcb97b70c 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -13,8 +13,6 @@ module Puppet::Parser::Functions DOC ) do |arguments| - function_deprecation([:join, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes']) - # Technically we support two arguments but only first is mandatory ... raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb index 19c6610fc..0ecd48f9e 100644 --- a/lib/puppet/parser/functions/keys.rb +++ b/lib/puppet/parser/functions/keys.rb @@ -7,8 +7,6 @@ module Puppet::Parser::Functions DOC ) do |arguments| - function_deprecation([:keys, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) - raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb index b3b027f1d..168da84b6 100644 --- a/lib/puppet/parser/functions/values.rb +++ b/lib/puppet/parser/functions/values.rb @@ -20,8 +20,6 @@ module Puppet::Parser::Functions DOC ) do |arguments| - function_deprecation([:values, 'This method is deprecated, this function is now shipped with Puppet in versions 5.5.0 and later. For more information please see Puppet 5.5.0 Release Notes.']) - raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/spec/acceptance/empty_spec.rb b/spec/acceptance/empty_spec.rb index 20d93d5d4..c5c63c043 100644 --- a/spec/acceptance/empty_spec.rb +++ b/spec/acceptance/empty_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'empty function' do +describe 'empty function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do describe 'success' do pp1 = <<-DOC $a = '' diff --git a/spec/acceptance/flatten_spec.rb b/spec/acceptance/flatten_spec.rb index cd93d5fdc..79d4854d8 100644 --- a/spec/acceptance/flatten_spec.rb +++ b/spec/acceptance/flatten_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'flatten function' do +describe 'flatten function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do describe 'success' do pp1 = <<-DOC $a = ["a","b",["c",["d","e"],"f","g"]] diff --git a/spec/acceptance/join_spec.rb b/spec/acceptance/join_spec.rb index 8e9ed80d2..233b953a0 100644 --- a/spec/acceptance/join_spec.rb +++ b/spec/acceptance/join_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'join function' do +describe 'join function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do describe 'success' do pp = <<-DOC $a = ['aaa','bbb','ccc'] diff --git a/spec/acceptance/keys_spec.rb b/spec/acceptance/keys_spec.rb index b3f4c47d8..9c4122c64 100644 --- a/spec/acceptance/keys_spec.rb +++ b/spec/acceptance/keys_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'keys function' do +describe 'keys function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do describe 'success' do pp = <<-DOC $a = {'aaa'=>'bbb','ccc'=>'ddd'} diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb index 9aed79b6d..b450dc7ba 100644 --- a/spec/acceptance/values_spec.rb +++ b/spec/acceptance/values_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'values function' do +describe 'values function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do describe 'success' do pp1 = <<-DOC $arg = { @@ -23,8 +23,7 @@ notice(inline_template('<%= @output.inspect %>')) DOC it 'handles non-hash arguments' do - expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{Requires hash}) if return_puppet_version < '5.5.0' - expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{expects a Hash value}) if return_puppet_version >= '5.5.0' + expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{Requires hash}) end end end diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index 9060b8435..c6bf1e44a 100644 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe 'empty' do +describe 'empty', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) @@ -19,21 +19,4 @@ it { is_expected.to run.with_params({}).and_return(true) } it { is_expected.to run.with_params('key' => 'value').and_return(false) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(0).and_return(false) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - scope.expects(:warning).with(includes('This method is deprecated')).never - is_expected.to run.with_params(0).and_return(false) - end - end end diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index 118ea6aa7..df9ce34c5 100644 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -1,33 +1,15 @@ require 'spec_helper' -# rubocop:disable Style/WordArray, Layout/SpaceAfterComma -describe 'flatten' do +describe 'flatten', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params([]).and_return([]) } it { is_expected.to run.with_params(['one']).and_return(['one']) } it { is_expected.to run.with_params([['one']]).and_return(['one']) } it { is_expected.to run.with_params(%w[a b c d e f g]).and_return(%w[a b c d e f g]) } it { is_expected.to run.with_params([['a', 'b', ['c', %w[d e], 'f', 'g']]]).and_return(%w[a b c d e f g]) } it { is_expected.to run.with_params(['ã', 'β', ['ĉ', %w[đ ẽ ƒ ġ]]]).and_return(%w[ã β ĉ đ ẽ ƒ ġ]) } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c']) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - scope.expects(:warning).with(includes('This method is deprecated')).never - is_expected.to run.with_params(['a', ['b', ['c']]]).and_return(['a','b','c']) - end - end end diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index f1a8e19d5..c24ee7614 100644 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' -describe 'join' do +describe 'join', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { pending('Current implementation ignores parameters after the second.') is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) } + it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) } it { is_expected.to run.with_params([]).and_return('') } it { is_expected.to run.with_params([], ':').and_return('') } @@ -17,21 +17,4 @@ it { is_expected.to run.with_params(%w[one two three]).and_return('onetwothree') } it { is_expected.to run.with_params(%w[one two three], ':').and_return('one:two:three') } it { is_expected.to run.with_params(%w[ōŋể ŧשợ ţђŕẽё], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') } - - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params([]).and_return('') - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - scope.expects(:warning).with(includes('This method is deprecated')).never - is_expected.to run.with_params([]).and_return('') - end - end end diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index 4adab7db6..23a870e2d 100644 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -1,44 +1,24 @@ require 'spec_helper' -describe 'keys' do +describe 'keys', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } it { is_expected.to run.with_params({}).and_return([]) } it { is_expected.to run.with_params('key' => 'value').and_return(['key']) } - - if Puppet.version < '5.5.0' - it 'returns the array of keys' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) - expect(result).to match_array(%w[key1 key2]) - end - - it 'runs with UTF8 and double byte characters', :if => Puppet.version < '5.5.0' do - result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) - expect(result).to match_array(%w[ҝểү キー]) - end + it 'returns the array of keys' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) + expect(result).to match_array(%w[key1 key2]) end - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params({}).and_return([]) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - scope.expects(:warning).with(includes('This method is deprecated')).never - is_expected.to run.with_params({}).and_return([]) - end + it 'runs with UTF8 and double byte characters' do + result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) + expect(result).to match_array(%w[ҝểү キー]) end end diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb index 7bad7b023..550c557ee 100644 --- a/spec/functions/length_spec.rb +++ b/spec/functions/length_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe 'length' do +describe 'length', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'length' expects 1 argument, got none}) } it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, %r{'length' expects 1 argument, got 2}) } - it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) } + it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) } it { is_expected.to run.with_params('1').and_return(1) } it { is_expected.to run.with_params('1.0').and_return(3) } it { is_expected.to run.with_params([]).and_return(0) } diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index d6d57d375..85554c6ac 100644 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -1,43 +1,24 @@ require 'spec_helper' -describe 'values' do +describe 'values', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { pending('Current implementation ignores parameters after the first.') is_expected.to run.with_params({}, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } if Puppet.version < '5.5.0' + it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } + it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } it { is_expected.to run.with_params({}).and_return([]) } it { is_expected.to run.with_params('key' => 'value').and_return(['value']) } - - if Puppet.version < '5.5.0' - it 'returns the array of values' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) - expect(result).to match_array(%w[value1 value2 value2]) - end - it 'runs with UTF8 and double byte characters' do - result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) - expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) - end + it 'returns the array of values' do + result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) + expect(result).to match_array(%w[value1 value2 value2]) end - context 'with deprecation warning' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - # Checking for deprecation warning, which should only be provoked when the env variable for it is set. - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('key' => 'value').and_return(['value']) - end - it 'displays no warning for deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'false' - scope.expects(:warning).with(includes('This method is deprecated')).never - is_expected.to run.with_params('key' => 'value').and_return(['value']) - end + it 'runs with UTF8 and double byte characters' do + result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) + expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) end end