summaryrefslogtreecommitdiff
path: root/spec/integration/parser/conditionals_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/integration/parser/conditionals_spec.rb')
-rw-r--r--spec/integration/parser/conditionals_spec.rb117
1 files changed, 117 insertions, 0 deletions
diff --git a/spec/integration/parser/conditionals_spec.rb b/spec/integration/parser/conditionals_spec.rb
new file mode 100644
index 000000000..82d950a06
--- /dev/null
+++ b/spec/integration/parser/conditionals_spec.rb
@@ -0,0 +1,117 @@
+require 'spec_helper'
+require 'puppet_spec/compiler'
+require 'matchers/resource'
+
+describe "Evaluation of Conditionals" do
+ include PuppetSpec::Compiler
+ include Matchers::Resource
+
+ shared_examples_for "a catalog built with conditionals" do
+ it "evaluates an if block correctly" do
+ catalog = compile_to_catalog(<<-CODE)
+ if( 1 == 1) {
+ notify { 'if': }
+ } elsif(2 == 2) {
+ notify { 'elsif': }
+ } else {
+ notify { 'else': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[if]")
+ end
+
+ it "evaluates elsif block" do
+ catalog = compile_to_catalog(<<-CODE)
+ if( 1 == 3) {
+ notify { 'if': }
+ } elsif(2 == 2) {
+ notify { 'elsif': }
+ } else {
+ notify { 'else': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[elsif]")
+ end
+
+ it "reaches the else clause if no expressions match" do
+ catalog = compile_to_catalog(<<-CODE)
+ if( 1 == 2) {
+ notify { 'if': }
+ } elsif(2 == 3) {
+ notify { 'elsif': }
+ } else {
+ notify { 'else': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[else]")
+ end
+
+ it "evalutes false to false" do
+ catalog = compile_to_catalog(<<-CODE)
+ if false {
+ } else {
+ notify { 'false': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[false]")
+ end
+
+ it "evaluates the string 'false' as true" do
+ catalog = compile_to_catalog(<<-CODE)
+ if 'false' {
+ notify { 'true': }
+ } else {
+ notify { 'false': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[true]")
+ end
+
+ it "evaluates undefined variables as false" do
+ catalog = compile_to_catalog(<<-CODE)
+ if $undef_var {
+ } else {
+ notify { 'undef': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[undef]")
+ end
+ end
+
+ context "current parser" do
+ before(:each) do
+ Puppet[:parser] = 'current'
+ end
+
+ it_behaves_like "a catalog built with conditionals"
+
+ it "evaluates empty string as false" do
+ catalog = compile_to_catalog(<<-CODE)
+ if '' {
+ notify { 'true': }
+ } else {
+ notify { 'empty': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[empty]")
+ end
+ end
+
+ context "future parser" do
+ before(:each) do
+ Puppet[:parser] = 'future'
+ end
+ it_behaves_like "a catalog built with conditionals"
+
+ it "evaluates empty string as true" do
+ catalog = compile_to_catalog(<<-CODE)
+ if '' {
+ notify { 'true': }
+ } else {
+ notify { 'empty': }
+ }
+ CODE
+ expect(catalog).to have_resource("Notify[true]")
+ end
+ end
+end