3 # We don't need this for the basic tests we're doing
4 # require 'spec_helper'
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
10 describe Puppet::Parser::Functions.function(:getvar) do
12 # Pulled from Dan's create_resources function
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
23 describe 'when calling getvar from puppet' do
25 it "should not compile when no arguments are passed" do
26 Puppet[:code] = 'getvar()'
28 expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
30 it "should not compile when too many arguments are passed" do
31 Puppet[:code] = 'getvar("foo::bar", "baz")'
33 expect { @scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
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' }
41 $foo = getvar("site::data::foo")
43 fail('getvar did not return what we expect')
47 @scope.compiler.compile