spec/unit/other/transobject.rb in puppet-0.24.9 vs spec/unit/other/transobject.rb in puppet-0.25.0

- old
+ new

@@ -37,56 +37,76 @@ newresource[param].should == @resource[param] end end end +describe Puppet::TransObject, " when converting to a Puppet::Resource" do + before do + @trans = Puppet::TransObject.new("/my/file", "file") + @trans["one"] = "test" + @trans["two"] = "other" + end + + it "should create a resource with the correct type and title" do + result = @trans.to_resource + result.type.should == "File" + result.title.should == "/my/file" + end + + it "should add all of its parameters to the created resource" do + @trans[:noop] = true + @trans.to_resource[:noop].should be_true + end + + it "should copy over the tags" do + @trans.tags = %w{foo bar} + result = @trans.to_resource + result.should be_tagged("foo") + result.should be_tagged("bar") + end +end + describe Puppet::TransObject, " when converting to a RAL resource" do before do @resource = Puppet::TransObject.new("/my/file", "file") @resource["one"] = "test" @resource["two"] = "other" end - it "should use the resource type's :create method to create the resource" do - type = mock 'resource type' - type.expects(:create).with(@resource).returns(:myresource) - Puppet::Type.expects(:type).with("file").returns(type) - @resource.to_type.should == :myresource + it "should use a Puppet::Resource to create the resource" do + resource = mock 'resource' + @resource.expects(:to_resource).returns resource + resource.expects(:to_ral).returns "myral" + @resource.to_ral.should == "myral" end - - it "should convert to a component instance if the resource type cannot be found" do - Puppet::Type.expects(:type).with("file").returns(nil) - @resource.expects(:to_component).returns(:mycomponent) - @resource.to_type.should == :mycomponent - end end describe Puppet::TransObject, " when converting to a RAL component instance" do before do @resource = Puppet::TransObject.new("/my/file", "one::two") @resource["one"] = "test" @resource["noop"] = "other" end it "should use a new TransObject whose name is a resource reference of the type and title of the original TransObject" do - Puppet::Type::Component.expects(:create).with { |resource| resource.type == "component" and resource.name == "One::Two[/my/file]" }.returns(:yay) + Puppet::Type::Component.expects(:new).with { |resource| resource.type == "component" and resource.name == "One::Two[/my/file]" }.returns(:yay) @resource.to_component.should == :yay end it "should pass the resource parameters on to the newly created TransObject" do - Puppet::Type::Component.expects(:create).with { |resource| resource["noop"] == "other" }.returns(:yay) + Puppet::Type::Component.expects(:new).with { |resource| resource["noop"] == "other" }.returns(:yay) @resource.to_component.should == :yay end it "should copy over the catalog" do @resource.catalog = "mycat" - Puppet::Type::Component.expects(:create).with { |resource| resource.catalog == "mycat" }.returns(:yay) + Puppet::Type::Component.expects(:new).with { |resource| resource.catalog == "mycat" }.returns(:yay) @resource.to_component end # LAK:FIXME This really isn't the design we want going forward, but it's # good enough for now. it "should not pass resource parameters that are not metaparams" do - Puppet::Type::Component.expects(:create).with { |resource| resource["one"].nil? }.returns(:yay) + Puppet::Type::Component.expects(:new).with { |resource| resource["one"].nil? }.returns(:yay) @resource.to_component.should == :yay end end