X-Git-Url: https://git.donarmstrong.com/?p=dsa-puppet.git;a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstaging%2Fspec%2Funit%2Fpuppet%2Fparser%2Ffunctions%2Fscope_defaults_spec.rb;fp=3rdparty%2Fmodules%2Fstaging%2Fspec%2Funit%2Fpuppet%2Fparser%2Ffunctions%2Fscope_defaults_spec.rb;h=50c460de73291ad6f4ac4e16dbe2425e99f6a55c;hp=0000000000000000000000000000000000000000;hb=269aa0e4ab1d106f521995e9e4beb8335acdbed6;hpb=d44d714d51cff79f225cae6a6d8f98f97d3000a5 diff --git a/3rdparty/modules/staging/spec/unit/puppet/parser/functions/scope_defaults_spec.rb b/3rdparty/modules/staging/spec/unit/puppet/parser/functions/scope_defaults_spec.rb new file mode 100644 index 00000000..50c460de --- /dev/null +++ b/3rdparty/modules/staging/spec/unit/puppet/parser/functions/scope_defaults_spec.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the scope_defaults function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("scope_defaults").should == "function_scope_defaults" + end + + it "should raise a ParseError if there is less than 2 arguments" do + expect{ scope.function_scope_defaults([]) }. + to raise_error(Puppet::ParseError) + end + + it "should raise a ParseError if there is more than 2 arguments" do + expect{ scope.function_scope_defaults(['exec', 'path', 'error']) }. + to raise_error(Puppet::ParseError) + end + + it "should return false for invalid resource" do + result = scope.function_scope_defaults(['foo', 'path']) + result.should(eq(false)) + end + + it "should return false for resource without default attributes" do + if scope.respond_to? :define_settings + scope.define_settings('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin")) + else + scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin")) + end + result = scope.function_scope_defaults(['Exec', 'foo']) + result.should(eq(false)) + end + + it "should return true for resource with default attributes" do + if scope.respond_to? :define_settings + scope.define_settings('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin")) + else + scope.setdefaults('Exec', Puppet::Parser::Resource::Param.new(:name => :path, :value => "/bin")) + end + result = scope.function_scope_defaults(['Exec', 'path']) + result.should(eq(true)) + end +end