From 72d23659513517389880ba13663a1d6380d538ca Mon Sep 17 00:00:00 2001 From: tphoney Date: Tue, 5 Jul 2016 09:56:42 +0100 Subject: (MODULES-3529)add deprecation function --- spec/functions/deprecation_spec.rb | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/functions/deprecation_spec.rb (limited to 'spec/functions/deprecation_spec.rb') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb new file mode 100644 index 0000000..bbabe48 --- /dev/null +++ b/spec/functions/deprecation_spec.rb @@ -0,0 +1,51 @@ +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) { + # this is to reset the strict variable to default + Puppet.settings[:strict] = :warning + } + + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError) } + + it 'should display a single warning' do + Puppet.expects(:warning).with(includes('heelo')) + is_expected.to run.with_params('key', 'heelo') + end + + it 'should display a single warning, despite multiple calls' do + Puppet.expects(:warning).with(includes('heelo')).once + is_expected.to run.with_params('key', 'heelo') + is_expected.to run.with_params('key', 'heelo') + end + + it 'should fail twice with message, with multiple calls. when strict= :error' do + Puppet.settings[:strict] = :error + Puppet.expects(:warning).with(includes('heelo')).never + is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/) + is_expected.to run.with_params('key', 'heelo').and_raise_error(RuntimeError, /deprecation. key. heelo/) + end + + it 'should display nothing, despite multiple calls. strict= :off' do + Puppet.settings[:strict] = :off + Puppet.expects(:warning).with(includes('heelo')).never + is_expected.to run.with_params('key', 'heelo') + is_expected.to run.with_params('key', 'heelo') + end + + after(:all) { + # this is to reset the strict variable to default + Puppet.settings[:strict] = :warning + } + end +end -- cgit v1.2.3 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/functions/deprecation_spec.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'spec/functions/deprecation_spec.rb') 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 -- cgit v1.2.3 From 39148468abbd9b8af74b776eb49f0a8388fc8541 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Mon, 15 Aug 2016 10:39:50 +0100 Subject: (maint) Switch 3.x deprecation() to use Puppet warning logger The deprecation function was calling the `Kernel#warn` function which prints to stderr, rather than the Puppet logger. This causes problems for Puppet module tests on Travis CI, which has a cap on the amount of stdout/err permitted in its logs and also prevents users from finding the deprecation warnings when running under a Puppet master. --- spec/functions/deprecation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions/deprecation_spec.rb') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index a596e24..c213190 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -46,7 +46,7 @@ else 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')) + scope.expects(:warning).with(includes('heelo')) is_expected.to run.with_params('key', 'heelo') end end -- cgit v1.2.3 From 6c6c6d8e3448e3072d590a0782237486e46bc88d Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Tue, 23 Aug 2016 15:02:39 +0100 Subject: Deprecation function to be mutable in all cases --- spec/functions/deprecation_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/functions/deprecation_spec.rb') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index c213190..4321c3d 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -42,6 +42,10 @@ if Puppet.version.to_f >= 4.0 end else describe 'deprecation' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" 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 From 8a8ebc4850abe4996056a2700a6a50ac7666a922 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Mon, 3 Oct 2016 14:12:32 +0100 Subject: Replace :context with :all in spec tests --- spec/functions/deprecation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions/deprecation_spec.rb') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index 4321c3d..9859833 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -42,7 +42,7 @@ if Puppet.version.to_f >= 4.0 end else describe 'deprecation' do - after(:context) do + after(:all) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end ENV['STDLIB_LOG_DEPRECATIONS'] = "true" -- cgit v1.2.3 From e501cb1b646e9741fb6f2510a1a3a434041a4d33 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Thu, 24 Nov 2016 16:32:15 +0000 Subject: Update deprecation tests to include future parser --- spec/functions/deprecation_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/functions/deprecation_spec.rb') diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index 9859833..cee4f1c 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -41,11 +41,14 @@ if Puppet.version.to_f >= 4.0 } end else + # Puppet version < 4 will use these tests. describe 'deprecation' do after(:all) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end - ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + before(:all) do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + end 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