]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 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
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 (file)
index 0000000..50c460d
--- /dev/null
@@ -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