3
require File.dirname(__FILE__) + '/../../spec_helper'
5
component = Puppet::Type.type(:component)
8
it "should have a :name attribute" do
9
component.attrclass(:name).should_not be_nil
12
it "should use Class as its type when a normal string is provided as the title" do
13
component.new(:name => "bar").ref.should == "Class[bar]"
16
it "should always produce a resource reference string as its title" do
17
component.new(:name => "bar").title.should == "Class[bar]"
20
it "should have a reference string equivalent to its title" do
21
comp = component.new(:name => "Foo[bar]")
22
comp.title.should == comp.ref
25
it "should alias itself to its reference if it has a catalog and the catalog does not already have a resource with the same reference" do
26
catalog = mock 'catalog'
27
catalog.expects(:resource).with("Foo[bar]").returns nil
29
catalog.expects(:alias).with { |resource, name| resource.is_a?(component) and name == "Foo[bar]" }
31
component.new(:name => "Foo[bar]", :catalog => catalog)
34
it "should not fail when provided an invalid value" do
35
comp = component.new(:name => "Foo[bar]")
36
lambda { comp[:yayness] = "ey" }.should_not raise_error
39
it "should return previously provided invalid values" do
40
comp = component.new(:name => "Foo[bar]")
42
comp[:yayness].should == "eh"
45
it "should correctly support metaparameters" do
46
comp = component.new(:name => "Foo[bar]", :require => "Foo[bar]")
47
comp.parameter(:require).should be_instance_of(component.attrclass(:require))
50
describe "when building up the path" do
51
it "should produce the class name if the component models a class" do
52
component.new(:name => "Class[foo]").pathbuilder.must == ["foo"]
55
it "should produce an empty string if the component models the 'main' class" do
56
component.new(:name => "Class[main]").pathbuilder.must == [""]
59
it "should produce a resource reference if the component does not model a class" do
60
component.new(:name => "Foo[bar]").pathbuilder.must == ["Foo[bar]"]