Sha256: f3a698cb787bd5cb560cec5fefd000f3fcaa73e8108de657354596cd6b9975c8

Contents?: true

Size: 1.98 KB

Versions: 19

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe Puppet::Parser::AST::IfStatement do
  before :each do
    @scope = Puppet::Parser::Scope.new
  end

  describe "when evaluating" do

    before :each do
      @test = stub 'test'
      @test.stubs(:safeevaluate).with(@scope)

      @stmt = stub 'stmt'
      @stmt.stubs(:safeevaluate).with(@scope)

      @else = stub 'else'
      @else.stubs(:safeevaluate).with(@scope)

      @ifstmt = Puppet::Parser::AST::IfStatement.new :test => @test, :statements => @stmt
      @ifelsestmt = Puppet::Parser::AST::IfStatement.new :test => @test, :statements => @stmt, :else => @else
    end

    it "should evaluate test" do
      Puppet::Parser::Scope.stubs(:true?).returns(false)

      @test.expects(:safeevaluate).with(@scope)

      @ifstmt.evaluate(@scope)
    end

    it "should evaluate if statements if test is true" do
      Puppet::Parser::Scope.stubs(:true?).returns(true)

      @stmt.expects(:safeevaluate).with(@scope)

      @ifstmt.evaluate(@scope)
    end

    it "should not evaluate if statements if test is false" do
      Puppet::Parser::Scope.stubs(:true?).returns(false)

      @stmt.expects(:safeevaluate).with(@scope).never

      @ifstmt.evaluate(@scope)
    end

    it "should evaluate the else branch if test is false" do
      Puppet::Parser::Scope.stubs(:true?).returns(false)

      @else.expects(:safeevaluate).with(@scope)

      @ifelsestmt.evaluate(@scope)
    end

    it "should not evaluate the else branch if test is true" do
      Puppet::Parser::Scope.stubs(:true?).returns(true)

      @else.expects(:safeevaluate).with(@scope).never

      @ifelsestmt.evaluate(@scope)
    end

    it "should reset ephemeral statements after evaluation" do
      @scope.expects(:ephemeral_level).returns(:level)
      Puppet::Parser::Scope.stubs(:true?).returns(true)

      @stmt.expects(:safeevaluate).with(@scope)
      @scope.expects(:unset_ephemeral_var).with(:level)

      @ifstmt.evaluate(@scope)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-2.6.18 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.17 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.16 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.15 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.14 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.13 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.12 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.11 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.10 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.9 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.8 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.7 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.6 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.5 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.4 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.3 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.2 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.1 spec/unit/parser/ast/ifstatement_spec.rb
puppet-2.6.0 spec/unit/parser/ast/ifstatement_spec.rb