summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDavid Schmitt <david.schmitt@puppet.com>2016-08-08 16:15:21 +0100
committerGitHub <noreply@github.com>2016-08-08 16:15:21 +0100
commite39fe01ea01719b97110341cacc4b4e2784a7d1a (patch)
tree620b3c0889386c88d0731f0b958f622d0b4d1bac /spec
parent2bf9187cf8971fad35b0ffebf7c49963ba35c850 (diff)
parent6e7e69fe203e042b28aacb01301c338d55448c5f (diff)
Merge pull request #629 from tphoney/MODULES-3533
(modules-3533) deprecation for 3.x number function
Diffstat (limited to 'spec')
-rw-r--r--spec/aliases/float_spec.rb28
-rw-r--r--spec/aliases/integer_spec.rb28
-rw-r--r--spec/aliases/numeric_spec.rb32
-rw-r--r--spec/fixtures/modules/test/manifests/float.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/integer.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/numeric.pp8
-rw-r--r--spec/functions/deprecation_spec.rb18
-rwxr-xr-xspec/functions/is_float_spec.rb7
-rwxr-xr-xspec/functions/is_integer_spec.rb7
-rwxr-xr-xspec/functions/is_numeric_spec.rb7
-rwxr-xr-xspec/functions/validate_integer_spec.rb6
-rwxr-xr-xspec/functions/validate_numeric_spec.rb6
12 files changed, 155 insertions, 8 deletions
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) }