summaryrefslogtreecommitdiff
path: root/spec/integration/parser/scope_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration/parser/scope_spec.rb')
-rw-r--r--spec/integration/parser/scope_spec.rb245
1 files changed, 94 insertions, 151 deletions
diff --git a/spec/integration/parser/scope_spec.rb b/spec/integration/parser/scope_spec.rb
index 1fd84f421..c10caa7f0 100644
--- a/spec/integration/parser/scope_spec.rb
+++ b/spec/integration/parser/scope_spec.rb
@@ -39,23 +39,27 @@ describe "Two step scoping for variables" do
Puppet[:parser] = 'future'
end
- describe "using plussignment to change in a new scope" do
- it "does not change a string in the parent scope" do
- # Expects to be able to concatenate string using +=
+ describe "using unsupported operators" do
+ it "issues an error for +=" do
expect do
- catalog = compile_to_catalog(<<-MANIFEST, Puppet::Node.new('the node'))
- $var = "top_msg"
- class override {
- $var += "override"
- include foo
- }
- class foo {
- notify { 'something': message => $var, }
+ catalog = compile_to_catalog(<<-MANIFEST)
+ $var = ["top_msg"]
+ node default {
+ $var += ["override"]
}
+ MANIFEST
+ end.to raise_error(/The operator '\+=' is no longer supported/)
+ end
- include override
+ it "issues an error for -=" do
+ expect do
+ catalog = compile_to_catalog(<<-MANIFEST)
+ $var = ["top_msg"]
+ node default {
+ $var -= ["top_msg"]
+ }
MANIFEST
- end.to raise_error(/The value 'top_msg' cannot be converted to Numeric/)
+ end.to raise_error(/The operator '-=' is no longer supported/)
end
end
@@ -184,54 +188,6 @@ describe "Two step scoping for variables" do
end
describe "when using shadowing and inheritance" do
- it "finds value define in the inherited node" do
- expect_the_message_to_be('parent_msg') do <<-MANIFEST
- $var = "top_msg"
- node parent {
- $var = "parent_msg"
- }
- node default inherits parent {
- include foo
- }
- class foo {
- notify { 'something': message => $var, }
- }
- MANIFEST
- end
- end
-
- it "finds top scope when the class is included before the node defines the var" do
- expect_the_message_to_be('top_msg') do <<-MANIFEST
- $var = "top_msg"
- node parent {
- include foo
- }
- node default inherits parent {
- $var = "default_msg"
- }
- class foo {
- notify { 'something': message => $var, }
- }
- MANIFEST
- end
- end
-
- it "finds top scope when the class is included before the node defines the var" do
- expect_the_message_to_be('top_msg') do <<-MANIFEST
- $var = "top_msg"
- node parent {
- include foo
- }
- node default inherits parent {
- $var = "default_msg"
- }
- class foo {
- notify { 'something': message => $var, }
- }
- MANIFEST
- end
- end
-
it "finds values in its local scope" do
expect_the_message_to_be('local_msg') do <<-MANIFEST
node default {
@@ -363,7 +319,7 @@ describe "Two step scoping for variables" do
$var = "inner baz"
}
- class bar inherits baz {
+ class bar inherits foo::baz {
notify { 'something': message => $var, }
}
}
@@ -651,80 +607,6 @@ describe "Two step scoping for variables" do
end
end
- describe "using plussignment to change in a new scope" do
-
- it "does not change an array in the parent scope" do
- expect_the_message_to_be('top_msg') do <<-MANIFEST
- $var = ["top_msg"]
- class override {
- $var += ["override"]
- include foo
- }
- class foo {
- notify { 'something': message => $var, }
- }
-
- include override
- MANIFEST
- end
- end
-
- it "concatenates two arrays" do
- expect_the_message_to_be(['top_msg', 'override']) do <<-MANIFEST
- $var = ["top_msg"]
- class override {
- $var += ["override"]
- notify { 'something': message => $var, }
- }
-
- include override
- MANIFEST
- end
- end
-
- it "leaves an array of arrays unflattened" do
- expect_the_message_to_be([['top_msg'], ['override']]) do <<-MANIFEST
- $var = [["top_msg"]]
- class override {
- $var += [["override"]]
- notify { 'something': message => $var, }
- }
-
- include override
- MANIFEST
- end
- end
-
- it "does not change a hash in the parent scope" do
- expect_the_message_to_be({"key"=>"top_msg"}) do <<-MANIFEST
- $var = { "key" => "top_msg" }
- class override {
- $var += { "other" => "override" }
- include foo
- }
- class foo {
- notify { 'something': message => $var, }
- }
-
- include override
- MANIFEST
- end
- end
-
- it "replaces a value of a key in the hash instead of merging the values" do
- expect_the_message_to_be({"key"=>"override"}) do <<-MANIFEST
- $var = { "key" => "top_msg" }
- class override {
- $var += { "key" => "override" }
- notify { 'something': message => $var, }
- }
-
- include override
- MANIFEST
- end
- end
- end
-
describe "when using an enc" do
it "places enc parameters in top scope" do
enc_node = Puppet::Node.new("the node", { :parameters => { "var" => 'from_enc' } })
@@ -757,20 +639,16 @@ describe "Two step scoping for variables" do
end
end
- it "evaluates enc classes in the node scope when there is a matching node" do
- enc_node = Puppet::Node.new("the_node", { :classes => ['foo'] })
-
- expect_the_message_to_be('from matching node', enc_node) do <<-MANIFEST
- node inherited {
- $var = "from inherited"
- }
+ it "overrides enc variables from a node scope var" do
+ enc_node = Puppet::Node.new("the_node", { :classes => ['foo'], :parameters => { 'enc_var' => 'Set from ENC.' } })
- node the_node inherits inherited {
- $var = "from matching node"
+ expect_the_message_to_be('ENC overridden in node', enc_node) do <<-MANIFEST
+ node the_node {
+ $enc_var = "ENC overridden in node"
}
class foo {
- notify { 'something': message => $var, }
+ notify { 'something': message => $enc_var, }
}
MANIFEST
end
@@ -782,7 +660,74 @@ describe "Two step scoping for variables" do
before :each do
Puppet[:parser] = 'current'
end
- it_behaves_like 'the scope' do
+
+ it_behaves_like 'the scope'
+
+ it "finds value define in the inherited node" do
+ expect_the_message_to_be('parent_msg') do <<-MANIFEST
+ $var = "top_msg"
+ node parent {
+ $var = "parent_msg"
+ }
+ node default inherits parent {
+ include foo
+ }
+ class foo {
+ notify { 'something': message => $var, }
+ }
+ MANIFEST
+ end
+ end
+
+ it "finds top scope when the class is included before the node defines the var" do
+ expect_the_message_to_be('top_msg') do <<-MANIFEST
+ $var = "top_msg"
+ node parent {
+ include foo
+ }
+ node default inherits parent {
+ $var = "default_msg"
+ }
+ class foo {
+ notify { 'something': message => $var, }
+ }
+ MANIFEST
+ end
+ end
+
+ it "finds top scope when the class is included before the node defines the var" do
+ expect_the_message_to_be('top_msg') do <<-MANIFEST
+ $var = "top_msg"
+ node parent {
+ include foo
+ }
+ node default inherits parent {
+ $var = "default_msg"
+ }
+ class foo {
+ notify { 'something': message => $var, }
+ }
+ MANIFEST
+ end
+ end
+
+ it "evaluates enc classes in the node scope when there is a matching node" do
+ enc_node = Puppet::Node.new("the_node", { :classes => ['foo'] })
+
+ expect_the_message_to_be('from matching node', enc_node) do <<-MANIFEST
+ node inherited {
+ $var = "from inherited"
+ }
+
+ node the_node inherits inherited {
+ $var = "from matching node"
+ }
+
+ class foo {
+ notify { 'something': message => $var, }
+ }
+ MANIFEST
+ end
end
end
@@ -790,9 +735,7 @@ describe "Two step scoping for variables" do
before :each do
Puppet[:parser] = 'future'
end
- it_behaves_like 'the scope' do
- end
- end
+ it_behaves_like 'the scope'
+ end
end
-