Sha256: b8da52779a19eed39999031a039afe3ba779d2a51bd2d00526a289cf47d46540

Contents?: true

Size: 1.86 KB

Versions: 92

Compression:

Stored size: 1.86 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

describe Puppet::Parser::AST::ResourceOverride do

  ast = Puppet::Parser::AST

  before :each do
    @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
    @scope = Puppet::Parser::Scope.new(@compiler)
    @params = ast::ASTArray.new({})
    @compiler.stubs(:add_override)
  end

  it "should evaluate the overriden object" do
    klass = stub 'klass', :title => "title", :type => "type"
    object = mock 'object'
    object.expects(:safeevaluate).with(@scope).returns(klass)
    ast::ResourceOverride.new(:object => object, :parameters => @params ).evaluate(@scope)
  end

  it "should tell the compiler to override the resource with our own" do
    @compiler.expects(:add_override)

    klass = stub 'klass', :title => "title", :type => "one"
    object = mock 'object', :safeevaluate => klass
    ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
  end

  it "should return the overriden resource directly when called with one item" do
    klass = stub 'klass', :title => "title", :type => "one"
    object = mock 'object', :safeevaluate => klass
    override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
    override.should be_an_instance_of(Puppet::Parser::Resource)
    override.title.should == "title"
    override.type.should == "One"
  end

  it "should return an array of overriden resources when called with an array of titles" do
    klass1 = stub 'klass1', :title => "title1", :type => "one"
    klass2 = stub 'klass2', :title => "title2", :type => "one"

    object = mock 'object', :safeevaluate => [klass1,klass2]

    override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
    override.should have(2).elements
    override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) }
  end

end

Version data entries

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.8.7 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.6 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.5 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.4 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.3 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.2 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.1 spec/unit/parser/ast/resource_override_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/parser/ast/resource_override_spec.rb