3 require File.dirname(__FILE__) + '/../spec_helper'
5 require 'puppet/resource_reference'
7 describe Puppet::ResourceReference do
8 it "should have a :title attribute" do
9 Puppet::ResourceReference.new(:file, "foo").title.should == "foo"
12 it "should canonize types to capitalized strings" do
13 Puppet::ResourceReference.new(:file, "foo").type.should == "File"
16 it "should canonize qualified types so all strings are capitalized" do
17 Puppet::ResourceReference.new("foo::bar", "foo").type.should == "Foo::Bar"
20 it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
21 ref = Puppet::ResourceReference.new(:component, "foo")
22 ref.type.should == "Class"
23 ref.title.should == "foo"
26 it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
27 ref = Puppet::ResourceReference.new(:component, "foo::bar[yay]")
28 ref.type.should == "Foo::Bar"
29 ref.title.should == "yay"
32 it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
33 ref = Puppet::ResourceReference.new(nil, "yay")
34 ref.type.should == "Class"
35 ref.title.should == "yay"
38 it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
39 ref = Puppet::ResourceReference.new(nil, "foo::bar[yay]")
40 ref.type.should == "Foo::Bar"
41 ref.title.should == "yay"
45 describe Puppet::ResourceReference, "when resolving resources without a catalog" do
46 it "should be able to resolve builtin resources from their types" do
47 Puppet::Type.type(:file).expects(:[]).with("myfile").returns(:myfile)
48 Puppet::ResourceReference.new(:file, "myfile").resolve.should == :myfile
51 it "should be able to resolve defined resources from Components" do
52 Puppet::Type.type(:component).expects(:[]).with("Foo::Bar[yay]").returns(:mything)
53 Puppet::ResourceReference.new("foo::bar", "yay").resolve.should == :mything
57 describe Puppet::ResourceReference, "when resolving resources with a catalog" do
58 it "should resolve all resources using the catalog" do
59 config = mock 'catalog'
60 ref = Puppet::ResourceReference.new("foo::bar", "yay")
63 config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
65 ref.resolve.should == :myresource