]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/staging/spec/unit/puppet/parser/functions/scope_defaults_spec.rb
add nanliu/staging to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / staging / spec / unit / puppet / parser / functions / scope_defaults_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe "the scope_defaults function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     Puppet::Parser::Functions.function("scope_defaults").should == "function_scope_defaults"
9   end
10
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)
14   end
15
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)
19   end
20
21   it "should return false for invalid resource" do
22     result = scope.function_scope_defaults(['foo', 'path'])
23     result.should(eq(false))
24   end
25
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"))
29     else
30       scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
31     end
32     result = scope.function_scope_defaults(['Exec', 'foo'])
33     result.should(eq(false))
34   end
35
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"))
39     else
40       scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin"))
41     end
42     result = scope.function_scope_defaults(['Exec', 'path'])
43     result.should(eq(true))
44   end
45 end