From 6e7e69fe203e042b28aacb01301c338d55448c5f Mon Sep 17 00:00:00 2001 From: tphoney Date: Wed, 3 Aug 2016 17:06:25 +0100 Subject: (modules-3533) deprecation for 3.x number function --- spec/aliases/float_spec.rb | 28 ++++++++++++++++++++++ spec/aliases/integer_spec.rb | 28 ++++++++++++++++++++++ spec/aliases/numeric_spec.rb | 32 +++++++++++++++++++++++++ spec/fixtures/modules/test/manifests/float.pp | 8 +++++++ spec/fixtures/modules/test/manifests/integer.pp | 8 +++++++ spec/fixtures/modules/test/manifests/numeric.pp | 8 +++++++ spec/functions/deprecation_spec.rb | 18 +++++++------- spec/functions/is_float_spec.rb | 7 ++++++ spec/functions/is_integer_spec.rb | 7 ++++++ spec/functions/is_numeric_spec.rb | 7 ++++++ spec/functions/validate_integer_spec.rb | 6 +++++ spec/functions/validate_numeric_spec.rb | 6 +++++ 12 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 spec/aliases/float_spec.rb create mode 100644 spec/aliases/integer_spec.rb create mode 100644 spec/aliases/numeric_spec.rb create mode 100644 spec/fixtures/modules/test/manifests/float.pp create mode 100644 spec/fixtures/modules/test/manifests/integer.pp create mode 100644 spec/fixtures/modules/test/manifests/numeric.pp (limited to 'spec') diff --git a/spec/aliases/float_spec.rb b/spec/aliases/float_spec.rb new file mode 100644 index 0000000..be31e43 --- /dev/null +++ b/spec/aliases/float_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.0 + describe 'test::float', type: :class do + describe 'accepts floats' do + [ + 3.7, + '3.7', + -3.7, + '-342.2315e-12', + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'rejects other values' do + [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x', 3, '3', -3, '-3'].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Float or Pattern(\[.*\]+)?/) } + end + end + end + end +end diff --git a/spec/aliases/integer_spec.rb b/spec/aliases/integer_spec.rb new file mode 100644 index 0000000..fbc8c19 --- /dev/null +++ b/spec/aliases/integer_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.0 + describe 'test::integer', type: :class do + describe 'accepts integers' do + [ + 3, + '3', + -3, + '-3', + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'rejects other values' do + [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x', 3.7, '3.7',-3.7, '-342.2315e-12' ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Integer, Pattern(\[.*\]+)?, or Array/) } + end + end + end + end +end diff --git a/spec/aliases/numeric_spec.rb b/spec/aliases/numeric_spec.rb new file mode 100644 index 0000000..9afe4ed --- /dev/null +++ b/spec/aliases/numeric_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.0 + describe 'test::numeric', type: :class do + describe 'accepts numerics' do + [ + 3, + '3', + -3, + '-3', + 3.7, + '3.7', + -3.7, + '-342.2315e-12', + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'rejects other values' do + [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x' ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Numeric, Pattern(\[.*\]+)?, or Array/) } + end + end + end + end +end diff --git a/spec/fixtures/modules/test/manifests/float.pp b/spec/fixtures/modules/test/manifests/float.pp new file mode 100644 index 0000000..03a603d --- /dev/null +++ b/spec/fixtures/modules/test/manifests/float.pp @@ -0,0 +1,8 @@ +# Class to test the Stdlib::Compat::Float type alias +class test::float( + Stdlib::Compat::Float $value, + ) { + + notice("Success") + +} diff --git a/spec/fixtures/modules/test/manifests/integer.pp b/spec/fixtures/modules/test/manifests/integer.pp new file mode 100644 index 0000000..a4f26df --- /dev/null +++ b/spec/fixtures/modules/test/manifests/integer.pp @@ -0,0 +1,8 @@ +# Class to test the Stdlib::Compat::Integer type alias +class test::integer( + Stdlib::Compat::Integer $value, + ) { + + notice("Success") + +} diff --git a/spec/fixtures/modules/test/manifests/numeric.pp b/spec/fixtures/modules/test/manifests/numeric.pp new file mode 100644 index 0000000..2657ebc --- /dev/null +++ b/spec/fixtures/modules/test/manifests/numeric.pp @@ -0,0 +1,8 @@ +# Class to test the Stdlib::Compat::Numeric type alias +class test::numeric( + Stdlib::Compat::Numeric $value, + ) { + + notice("Success") + +} diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index bbabe48..a596e24 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -1,13 +1,5 @@ require 'spec_helper' -if ENV["FUTURE_PARSER"] == 'yes' - describe 'deprecation' do - pending 'teach rspec-puppet to load future-only functions under 3.7.5' do - it { is_expected.not_to eq(nil) } - end - end -end - if Puppet.version.to_f >= 4.0 describe 'deprecation' do before(:each) { @@ -48,4 +40,14 @@ if Puppet.version.to_f >= 4.0 Puppet.settings[:strict] = :warning } end +else + describe 'deprecation' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + it 'should display a single warning' do + scope.expects(:warn).with(includes('heelo')) + is_expected.to run.with_params('key', 'heelo') + end + end end diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb index ffff971..267d9c6 100755 --- a/spec/functions/is_float_spec.rb +++ b/spec/functions/is_float_spec.rb @@ -2,6 +2,13 @@ require 'spec_helper' describe 'is_float' do it { is_expected.not_to eq(nil) } + + # Checking for deprecation warning + it 'should display a single deprecation' do + scope.expects(:warn).with(includes('This method is deprecated')) + is_expected.to run.with_params(3) + end + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 67263c1..49550c7 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -2,6 +2,13 @@ require 'spec_helper' describe 'is_integer' do it { is_expected.not_to eq(nil) } + + # Checking for deprecation warning + it 'should display a single deprecation' do + scope.expects(:warn).with(includes('This method is deprecated')) + is_expected.to run.with_params(3) + end + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb index d0f5a6e..b7de051 100755 --- a/spec/functions/is_numeric_spec.rb +++ b/spec/functions/is_numeric_spec.rb @@ -2,6 +2,13 @@ require 'spec_helper' describe 'is_numeric' do it { is_expected.not_to eq(nil) } + + # Checking for deprecation warning + it 'should display a single deprecation' do + scope.expects(:warn).with(includes('This method is deprecated')) + is_expected.to run.with_params(3) + end + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb index 4c0a9d7..0eeab1e 100755 --- a/spec/functions/validate_integer_spec.rb +++ b/spec/functions/validate_integer_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe 'validate_integer' do + # Checking for deprecation warning + it 'should display a single deprecation' do + scope.expects(:warn).with(includes('This method is deprecated')) + is_expected.to run.with_params(3) + end + describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb index 9b8eb0e..2e5561e 100755 --- a/spec/functions/validate_numeric_spec.rb +++ b/spec/functions/validate_numeric_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe 'validate_numeric' do + # Checking for deprecation warning + it 'should display a single deprecation' do + scope.expects(:warn).with(includes('This method is deprecated')) + is_expected.to run.with_params(3) + end + describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } -- cgit v1.2.3