4 describe "the scope_defaults function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 Puppet::Parser::Functions.function("scope_defaults").should == "function_scope_defaults"
11 it "should raise a ParseError if there is less than 2 arguments" do
12 expect{ scope.function_scope_defaults([]) }.
13 to raise_error(Puppet::ParseError)
16 it "should raise a ParseError if there is more than 2 arguments" do
17 expect{ scope.function_scope_defaults(['exec', 'path', 'error']) }.
18 to raise_error(Puppet::ParseError)
21 it "should return false for invalid resource" do
22 result = scope.function_scope_defaults(['foo', 'path'])
23 result.should(eq(false))
26 it "should return false for resource without default attributes" do
27 if scope.respond_to? :define_settings
28 scope.define_settings('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
30 scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
32 result = scope.function_scope_defaults(['Exec', 'foo'])
33 result.should(eq(false))
36 it "should return true for resource with default attributes" do
37 if scope.respond_to? :define_settings
38 scope.define_settings('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
40 scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
42 result = scope.function_scope_defaults(['Exec', 'path'])
43 result.should(eq(true))