From f3e79ddcd56a221c7799b35efde7e9803a5c7923 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 1 Jun 2015 12:21:59 +0100 Subject: Convert tests to use plain rspec-puppet Tests in the new style produces the following documentation output: abs should not eq nil should run abs() and raise an Puppet::ParseError should run abs(-34) and return 34 should run abs("-34") and return 34 should run abs(34) and return 34 should run abs("34") and return 34 --- spec/functions/is_integer_spec.rb | 88 ++++++++++----------------------------- 1 file changed, 22 insertions(+), 66 deletions(-) (limited to 'spec/functions/is_integer_spec.rb') diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index f0cbca8..67263c1 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -1,69 +1,25 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe "the is_integer function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = scope.function_is_integer(["3"]) - expect(result).to(eq(true)) - end - - it "should return true if a negative integer" do - result = scope.function_is_integer(["-7"]) - expect(result).to(eq(true)) - end - - it "should return false if a float" do - result = scope.function_is_integer(["3.2"]) - expect(result).to(eq(false)) - end - - it "should return false if a string" do - result = scope.function_is_integer(["asdf"]) - expect(result).to(eq(false)) - end - - it "should return true if an integer is created from an arithmetical operation" do - result = scope.function_is_integer([3*2]) - expect(result).to(eq(true)) - end - - it "should return false if an array" do - result = scope.function_is_numeric([["asdf"]]) - expect(result).to(eq(false)) - end - - it "should return false if a hash" do - result = scope.function_is_numeric([{"asdf" => false}]) - expect(result).to(eq(false)) - end - - it "should return false if a boolean" do - result = scope.function_is_numeric([true]) - expect(result).to(eq(false)) - end - - it "should return false if a whitespace is in the string" do - result = scope.function_is_numeric([" -1324"]) - expect(result).to(eq(false)) - end - - it "should return false if it is zero prefixed" do - result = scope.function_is_numeric(["0001234"]) - expect(result).to(eq(false)) - end - - it "should return false if it is wrapped inside an array" do - result = scope.function_is_numeric([[1234]]) - expect(result).to(eq(false)) - end +describe 'is_integer' 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 { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + + it { is_expected.to run.with_params(3).and_return(true) } + it { is_expected.to run.with_params('3').and_return(true) } + it { is_expected.to run.with_params(-3).and_return(true) } + it { is_expected.to run.with_params('-3').and_return(true) } + + it { is_expected.to run.with_params(3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } + it { is_expected.to run.with_params(-3.7).and_return(false) } + it { is_expected.to run.with_params('3.7').and_return(false) } + + it { is_expected.to run.with_params('one').and_return(false) } + it { is_expected.to run.with_params([]).and_return(false) } + it { is_expected.to run.with_params([1]).and_return(false) } + it { is_expected.to run.with_params({}).and_return(false) } + it { is_expected.to run.with_params(true).and_return(false) } + it { is_expected.to run.with_params(false).and_return(false) } + it { is_expected.to run.with_params('0001234').and_return(false) } 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/is_integer_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/functions/is_integer_spec.rb') 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) } -- 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/is_integer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions/is_integer_spec.rb') diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 49550c7..2d68731 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -5,7 +5,7 @@ describe 'is_integer' do # Checking for deprecation warning it 'should display a single deprecation' do - scope.expects(:warn).with(includes('This method is deprecated')) + scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params(3) 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/is_integer_spec.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'spec/functions/is_integer_spec.rb') diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 2d68731..4b5dd21 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -1,14 +1,9 @@ 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(:warning).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) } @@ -16,7 +11,7 @@ describe 'is_integer' do it { is_expected.to run.with_params('3').and_return(true) } it { is_expected.to run.with_params(-3).and_return(true) } it { is_expected.to run.with_params('-3').and_return(true) } - + it { is_expected.to run.with_params(3.7).and_return(false) } it { is_expected.to run.with_params('3.7').and_return(false) } it { is_expected.to run.with_params(-3.7).and_return(false) } @@ -29,4 +24,22 @@ describe 'is_integer' do it { is_expected.to run.with_params(true).and_return(false) } it { is_expected.to run.with_params(false).and_return(false) } it { is_expected.to run.with_params('0001234').and_return(false) } + + context 'Checking for deprecation warning' do + after(:context) 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 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(50).and_return(true) + end + it 'should display 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(50).and_return(true) + end + end + end -- 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/is_integer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions/is_integer_spec.rb') diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 4b5dd21..b296830 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -26,7 +26,7 @@ describe 'is_integer' do it { is_expected.to run.with_params('0001234').and_return(false) } context 'Checking for deprecation warning' do - after(:context) do + after(:all) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end # Checking for deprecation warning, which should only be provoked when the env variable for it is set. -- cgit v1.2.3