summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions/include_spec.rb
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-07-27 10:20:27 -0700
committerJesse Wolfe <jes5199@gmail.com>2010-07-27 10:20:45 -0700
commitd5db8db116aff58215ab0feebd7ec02086040f51 (patch)
tree58489a37bd0ee14b3d053a0e23f9638b4f6205e7 /spec/unit/parser/functions/include_spec.rb
parent865282ae7b9332fdbdfa51b2814755b8a13d244b (diff)
parentb53e7d78e2e87571ae53170e9716b9ccd75da6e2 (diff)
downloadpuppet-d5db8db116aff58215ab0feebd7ec02086040f51.tar.gz
puppet-d5db8db116aff58215ab0feebd7ec02086040f51.tar.xz
puppet-d5db8db116aff58215ab0feebd7ec02086040f51.zip
Merge branch 'next'
This synchronizes the 2.7 master branch with 2.6.1RC1
Diffstat (limited to 'spec/unit/parser/functions/include_spec.rb')
-rw-r--r--spec/unit/parser/functions/include_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/include_spec.rb b/spec/unit/parser/functions/include_spec.rb
new file mode 100644
index 000000000..e5f051906
--- /dev/null
+++ b/spec/unit/parser/functions/include_spec.rb
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the 'include' function" do
+
+ before :each do
+ Puppet::Node::Environment.stubs(:current).returns(nil)
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+ # MQR TODO: Without the following stub these tests cause hundreds of spurious errors in
+ # subsequent tests. With it, there are no spurious failures and all but one
+ # of the tests (marked pending, bellow) fail. This needs a better solution.
+ Puppet::Parser::Resource.stubs(:new).with('stage', :main, :scope => @scope).returns 'foo'
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("include").should == "function_include"
+ end
+
+ it "should include a single class" do
+ inc = "foo"
+ @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == [inc]}.returns([inc])
+ @scope.function_include("foo")
+ end
+
+ it "should include multiple classes" do
+ inc = ["foo","bar"]
+ @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == inc}.returns(inc)
+ @scope.function_include(["foo","bar"])
+ end
+
+ it "should not lazily evaluate the included class" do
+ @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| lazy == false}.returns("foo")
+ @scope.function_include("foo")
+ end
+
+ it "should allow a parent to include its child" do
+ pending "Resolution of MQR TODO item, above"
+ @parent_type = Puppet::Resource::Type.new(:hostclass, "parent")
+ @parent_resource = Puppet::Parser::Resource.new(:hostclass, "parent", :scope => @scope)
+ @subscope = @parent_type.subscope(@scope,@parent_resource)
+ @scope.environment.known_resource_types.stubs(:find_hostclass).with{|nses,name| name.downcase == "parent"}.returns(@parent_type)
+
+ @type = Puppet::Resource::Type.new(:hostclass, "foo")
+ @type.stubs(:parent_scope).returns(@subscope)
+ @type.parent = "parent"
+ @resource = Puppet::Parser::Resource.new(:hostclass, "foo", :scope => @subscope)
+ @resource.stubs(:resource_type).returns(@type)
+ @scope.environment.known_resource_types.stubs(:find_hostclass).with{|nses,name| name.downcase == "foo"}.returns(@parent_type)
+ Puppet::Resource.stubs(:new).returns(@resource)
+ Puppet::Parser::Resource.stubs(:new).returns(@resource)
+ lambda { @subscope.function_include("foo") }.should_not raise_error
+ end
+end