summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-24 14:08:14 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 12:47:32 -0700
commit10230cfc28e77dde127c157b7238fee2fc378969 (patch)
tree2553d228a877ddc3b912bfb25bee9b8c70338878 /spec
parente5609ffefb4132049a969d88f74138058fe78694 (diff)
downloadpuppet-10230cfc28e77dde127c157b7238fee2fc378969.tar.gz
puppet-10230cfc28e77dde127c157b7238fee2fc378969.tar.xz
puppet-10230cfc28e77dde127c157b7238fee2fc378969.zip
Step towards #5027 -- scopes should know if they are dynamic
The logic for distinguishing dynamic / static scopes was borrowed from Nick & Paul's patch, the main differences here being 1) calling it "dynamic" (true/ false) rather than "parent_relationship" (:inherited/:dynamic) 2) aligning the default so that it only needs to get set in one place (the one that will eventually go away) and 3) setting it on createion rather than with a setter. Setting it in one place, on creation, also makes it easier to see that anytime we access a scope it will have the correct setting of Scope#dynamic and that this does not change. This commit also contains a minor refactor (removing Type#subscope) that is not strictly tied to the main purpose but lies in the direction we are needing to go and it simplified things to do it now.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/parser/scope_spec.rb8
-rwxr-xr-xspec/unit/resource/type_spec.rb36
2 files changed, 12 insertions, 32 deletions
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 17f485c03..8215535dd 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -73,6 +73,14 @@ describe Puppet::Parser::Scope do
Puppet::Parser::Scope.new.singleton_class.ancestors.should be_include(mod)
end
+
+ it "should remember if it is dynamic" do
+ (!!Puppet::Parser::Scope.new(:dynamic => true).dynamic).should == true
+ end
+
+ it "should assume it is not dynamic" do
+ (!Puppet::Parser::Scope.new.dynamic).should == true
+ end
end
describe "when looking up a variable" do
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index b6a5f6982..45c880440 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -237,35 +237,6 @@ describe Puppet::Resource::Type do
end
end
- describe "when creating a subscope" do
- before do
- @scope = stub 'scope', :newscope => nil
- @resource = stub 'resource'
- @type = Puppet::Resource::Type.new(:hostclass, "foo")
- end
-
- it "should return a new scope created with the provided scope as the parent" do
- @scope.expects(:newscope).returns "foo"
- @type.subscope(@scope, @resource).should == "foo"
- end
-
- it "should set the source as itself" do
- @scope.expects(:newscope).with { |args| args[:source] == @type }
- @type.subscope(@scope, @resource)
- end
-
- it "should set the scope's namespace to its namespace" do
- @type.expects(:namespace).returns "yayness"
- @scope.expects(:newscope).with { |args| args[:namespace] == "yayness" }
- @type.subscope(@scope, @resource)
- end
-
- it "should set the scope's resource to the provided resource" do
- @scope.expects(:newscope).with { |args| args[:resource] == @resource }
- @type.subscope(@scope, @resource)
- end
- end
-
describe "when setting its parameters in the scope" do
before do
@scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source"))
@@ -465,7 +436,7 @@ describe Puppet::Resource::Type do
it "should set all of its parameters in a subscope" do
subscope = stub 'subscope', :compiler => @compiler
- @type.expects(:subscope).with(@scope, @resource).returns subscope
+ @scope.expects(:newscope).with(:source => @type, :dynamic => true, :namespace => 'foo', :resource => @resource).returns subscope
@type.expects(:set_resource_parameters).with(@resource, subscope)
@type.evaluate_code(@resource)
@@ -493,8 +464,9 @@ describe Puppet::Resource::Type do
it "should evaluate the AST code if any is provided" do
code = stub 'code'
@type.stubs(:code).returns code
- @type.stubs(:subscope).returns stub_everything("subscope", :compiler => @compiler)
- code.expects(:safeevaluate).with @type.subscope
+ subscope = stub_everything("subscope", :compiler => @compiler)
+ @scope.stubs(:newscope).returns subscope
+ code.expects(:safeevaluate).with subscope
@type.evaluate_code(@resource)
end