summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/ast/resource_override.rb
blob: 3fbeb323c9efc67c7d7a39da6e1ee6cc59cb24f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby

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

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

    AST = Puppet::Parser::AST

    before :each do
        @compiler = stub 'compiler'
        @scope = Puppet::Parser::Scope.new(:compiler => @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, :params => @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 , :params => @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 , :params => @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 , :params => @params).evaluate(@scope)        
        override.should have(2).elements
        override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) }
    end

end