Sha256: dafd167e91375a86a1baeb5339f35729fb2280025fe73c4518d685b7c805529e

Contents?: true

Size: 1.83 KB

Versions: 19

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby

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

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

  describe "when evaluating" do

    it "should evaluate arguments" do
      name = mock 'name'
      value = mock 'value'

      name.expects(:safeevaluate).with(@scope)
      value.expects(:safeevaluate).with(@scope)

      vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
        :line => nil
      vardef.evaluate(@scope)
    end

    it "should be in append=false mode if called without append" do
      name = stub 'name', :safeevaluate => "var"
      value = stub 'value', :safeevaluate => "1"

      @scope.expects(:setvar).with { |name,value,options| options[:append] == nil }

      vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
        :line => nil
      vardef.evaluate(@scope)
    end

    it "should call scope in append mode if append is true" do
      name = stub 'name', :safeevaluate => "var"
      value = stub 'value', :safeevaluate => "1"

      @scope.expects(:setvar).with { |name,value,options| options[:append] == true }

      vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
        :line => nil, :append => true
      vardef.evaluate(@scope)
    end

    describe "when dealing with hash" do
      it "should delegate to the HashOrArrayAccess assign" do
        access = stub 'name'
        access.stubs(:is_a?).with(Puppet::Parser::AST::HashOrArrayAccess).returns(true)
        value = stub 'value', :safeevaluate => "1"
        vardef = Puppet::Parser::AST::VarDef.new :name => access, :value => value, :file => nil, :line => nil

        access.expects(:assign).with(@scope, '1')

        vardef.evaluate(@scope)
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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