summaryrefslogtreecommitdiff
path: root/spec/functions/getvar_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functions/getvar_spec.rb')
-rwxr-xr-xspec/functions/getvar_spec.rb46
1 files changed, 16 insertions, 30 deletions
diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb
index 87ab9b5..54f1842 100755
--- a/spec/functions/getvar_spec.rb
+++ b/spec/functions/getvar_spec.rb
@@ -1,37 +1,23 @@
-#! /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
+ it { is_expected.to run.with_params('$::foo').and_return(nil) }
- 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/)
- 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')
- }
+ context 'given variables in namespaces' do
+ let(:pre_condition) {
+ <<-'ENDofPUPPETcode'
+ class site::data { $foo = 'baz' }
+ include site::data
ENDofPUPPETcode
- scope.compiler.compile
- end
+ }
+
+ 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') }
+ it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
end
end