From b664fec30f8b7d8a4dd8621d8064df9b9789169b Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 23 Apr 2015 16:37:01 -0700 Subject: specs: loosen certain error expectations to make tests pass on future parser --- spec/functions/validate_ipv6_address_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'spec/functions/validate_ipv6_address_spec.rb') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index a839d90..e87b372 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -41,9 +41,7 @@ describe Puppet::Parser::Functions.function(:validate_ipv6_address) do describe "when given numbers" do it "should not compile" do Puppet[:code] = "validate_ipv6_address(1, 2)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) + expect { scope.compiler.compile }.to raise_error end end end -- cgit v1.2.3 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/validate_ipv6_address_spec.rb | 85 +++++++++------------------- 1 file changed, 26 insertions(+), 59 deletions(-) (limited to 'spec/functions/validate_ipv6_address_spec.rb') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index e87b372..7aaf006 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -1,65 +1,32 @@ -#! /usr/bin/env ruby -S rspec - -require "spec_helper" - -describe Puppet::Parser::Functions.function(:validate_ipv6_address) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - describe "when calling validate_ipv6_address from puppet" do - describe "when given IPv6 address strings" do - it "should compile with one argument" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::')" - scope.compiler.compile - end - - it "should compile with multiple arguments" do - Puppet[:code] = "validate_ipv6_address('3ffe:0505:0002::', '3ffe:0505:0001::')" - scope.compiler.compile - end - end - - describe "when given an ipv4 address" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('1.2.3.4')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) - end +require 'spec_helper' + +describe 'validate_ipv6_address' do + 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) } + + describe 'valid inputs' do + it { is_expected.to run.with_params('3ffe:0505:0002::') } + it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } + it { is_expected.to run.with_params('::1/64') } + it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } end - describe "when given other strings" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address('hello', 'world')" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } end end - - # 1.8.7 is EOL'd and also absolutely insane about ipv6 - unless RUBY_VERSION == '1.8.7' - describe "when given numbers" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(1, 2)" - expect { scope.compiler.compile }.to raise_error - end - end - end - - describe "when given booleans" do - it "should not compile" do - Puppet[:code] = "validate_ipv6_address(true, false)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a string/) - end - end - - it "should not compile when no arguments are passed" do - Puppet[:code] = "validate_ipv6_address()" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end end end -- cgit v1.2.3 From 6d185bdaa19f698270a0df4b0a0c05618864b955 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Tue, 16 Aug 2016 11:55:05 +0100 Subject: Deprecation of ip functions --- spec/functions/validate_ipv6_address_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/functions/validate_ipv6_address_spec.rb') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 7aaf006..3afab56 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -10,6 +10,10 @@ describe 'validate_ipv6_address' do it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } it { is_expected.to run.with_params('::1/64') } it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } + it 'should display a single deprecation' do + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('3ffe:0505:0002::') + end end describe 'invalid inputs' do -- 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/validate_ipv6_address_spec.rb | 62 +++++++++++++++++----------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'spec/functions/validate_ipv6_address_spec.rb') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 3afab56..87b535e 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -1,36 +1,50 @@ require 'spec_helper' describe 'validate_ipv6_address' do + 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) } + end - describe 'valid inputs' do - it { is_expected.to run.with_params('3ffe:0505:0002::') } - it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } - it { is_expected.to run.with_params('::1/64') } - it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('3ffe:0505:0002::') - end + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 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('3ffe:0505:0002::') + 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('3ffe:0505:0002::') end + end + + describe 'valid inputs' do + it { is_expected.to run.with_params('3ffe:0505:0002::') } + it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } + it { is_expected.to run.with_params('::1/64') } + it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } + end - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } - end + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } 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/validate_ipv6_address_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/functions/validate_ipv6_address_spec.rb') diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 87b535e..78810d4 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -8,7 +8,7 @@ describe 'validate_ipv6_address' do end context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 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