]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / modules / stdlib / spec / unit / puppet / parser / functions / getvar_spec.rb
1 require 'puppet'
2
3 # We don't need this for the basic tests we're doing
4 # require 'spec_helper'
5
6 # Dan mentioned that Nick recommended the function method call
7 # to return the string value for the test description.
8 # this will not even try the test if the function cannot be
9 # loaded.
10 describe Puppet::Parser::Functions.function(:getvar) do
11
12   # Pulled from Dan's create_resources function
13   def get_scope
14     @topscope = Puppet::Parser::Scope.new
15     # This is necessary so we don't try to use the compiler to discover our parent.
16     @topscope.parent = nil
17     @scope = Puppet::Parser::Scope.new
18     @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => 'production'))
19     @scope.parent = @topscope
20     @compiler = @scope.compiler
21   end
22
23   describe 'when calling getvar from puppet' do
24
25     it "should not compile when no arguments are passed" do
26       Puppet[:code] = 'getvar()'
27       get_scope
28       expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
29     end
30     it "should not compile when too many arguments are passed" do
31       Puppet[:code] = 'getvar("foo::bar", "baz")'
32       get_scope
33       expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
34     end
35
36     it "should lookup variables in other namespaces" do
37       pending "Puppet doesn't appear to think getvar is an rvalue function... BUG?"
38       Puppet[:code] = <<-'ENDofPUPPETcode'
39         class site::data { $foo = 'baz' }
40         include site::data
41         $foo = getvar("site::data::foo")
42         if $foo != 'baz' {
43           fail('getvar did not return what we expect')
44         }
45       ENDofPUPPETcode
46       get_scope
47       @scope.compiler.compile
48     end
49
50   end
51
52 end
53