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/getvar_spec.rb | 47 +++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) (limited to 'spec/functions/getvar_spec.rb') diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 87ab9b5..37125d1 100755 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -1,37 +1,28 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' -describe Puppet::Parser::Functions.function(:getvar) do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - describe 'when calling getvar from puppet' do +describe 'getvar' 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('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } - it "should not compile when no arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar()' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) - end + context 'given variables in namespaces' do + let(:pre_condition) { + <<-'ENDofPUPPETcode' + class site::data { $foo = 'baz' } + include site::data + ENDofPUPPETcode + } - it "should not compile when too many arguments are passed" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = '$foo = getvar("foo::bar", "baz")' - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + it { is_expected.to run.with_params('site::data::foo').and_return('baz') } + it { is_expected.to run.with_params('::site::data::foo').and_return('baz') } + + context 'with strict variable checking', :if => RSpec.configuration.strict_variables do + it { is_expected.to run.with_params('::site::data::bar').and_raise_error(ArgumentError, /undefined_variable/) } end - it "should lookup variables in other namespaces" do - skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ - Puppet[:code] = <<-'ENDofPUPPETcode' - class site::data { $foo = 'baz' } - include site::data - $foo = getvar("site::data::foo") - if $foo != 'baz' { - fail('getvar did not return what we expect') - } - ENDofPUPPETcode - scope.compiler.compile + context 'without strict variable checking', :unless => RSpec.configuration.strict_variables do + it { is_expected.to run.with_params('::site::data::bar').and_return(nil) } end end end -- cgit v1.2.3 From c9e093f8d3d31f73b021e247f940c1f60be9c1e1 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 12 Jun 2015 14:42:09 +0100 Subject: (maint) getvar: update spec to match implementation --- spec/functions/getvar_spec.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'spec/functions/getvar_spec.rb') diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 37125d1..6ab137e 100755 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -16,13 +16,6 @@ describe 'getvar' do it { is_expected.to run.with_params('site::data::foo').and_return('baz') } it { is_expected.to run.with_params('::site::data::foo').and_return('baz') } - - context 'with strict variable checking', :if => RSpec.configuration.strict_variables do - it { is_expected.to run.with_params('::site::data::bar').and_raise_error(ArgumentError, /undefined_variable/) } - end - - context 'without strict variable checking', :unless => RSpec.configuration.strict_variables do - it { is_expected.to run.with_params('::site::data::bar').and_return(nil) } - end + it { is_expected.to run.with_params('::site::data::bar').and_return(nil) } end end -- cgit v1.2.3 From 729e076f1d5eee87c22fee1253dd6cac039f8509 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Sat, 8 Oct 2016 20:06:32 +0100 Subject: Add testcase for #665 @keymone added information on how to reproduce his issue, so here's the test case that would fail without his change. --- spec/functions/getvar_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/functions/getvar_spec.rb') diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 6ab137e..54f1842 100755 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -6,6 +6,8 @@ describe 'getvar' do it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + it { is_expected.to run.with_params('$::foo').and_return(nil) } + context 'given variables in namespaces' do let(:pre_condition) { <<-'ENDofPUPPETcode' -- cgit v1.2.3