diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2008-10-04 00:16:17 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-10-05 14:53:13 +1100 |
| commit | 79bb1f201c1479a15fa2f0f8ad5467bd357ed707 (patch) | |
| tree | 6887338bab7a90d4ca1f4e56282e4baeddc63673 /spec/unit/parser/ast/resource_reference.rb | |
| parent | 750e9abc64af58e547e7b1ad5698c71feb071bf6 (diff) | |
| download | puppet-79bb1f201c1479a15fa2f0f8ad5467bd357ed707.tar.gz puppet-79bb1f201c1479a15fa2f0f8ad5467bd357ed707.tar.xz puppet-79bb1f201c1479a15fa2f0f8ad5467bd357ed707.zip | |
Rspec Tests for #381.
Moved part of the old resource reference tests to rspec.
Diffstat (limited to 'spec/unit/parser/ast/resource_reference.rb')
| -rwxr-xr-x | spec/unit/parser/ast/resource_reference.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/resource_reference.rb b/spec/unit/parser/ast/resource_reference.rb new file mode 100755 index 000000000..e4b7c763b --- /dev/null +++ b/spec/unit/parser/ast/resource_reference.rb @@ -0,0 +1,63 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::ResourceReference do + + AST = Puppet::Parser::AST + + before :each do + @scope = Puppet::Parser::Scope.new() + end + + def newref(title, type) + title = stub 'title', :safeevaluate => title + ref = AST::ResourceReference.new(:type => type, :title => title) + end + + it "should evaluate correctly reference to builtin types" do + newref("/tmp/yay", "File").evaluate(@scope).to_s.should == "File[/tmp/yay]" + end + + %{ "one::two" "one-two"}.each do |type| + it "should evaluate correctly reference to define" do + klass = stub 'klass', :title => "three", :classname => type + @scope.stubs(:finddefine).returns(klass) + + newref("three", type).evaluate(@scope).to_ref.should == Puppet::Parser::Resource::Reference.new( :type => type, :title => "three" ).to_ref + end + end + + it "should be able to call qualified_class" do + klass = stub 'klass', :title => "three", :classname => "one" + @scope.expects(:findclass).with("one").returns(klass) + newref("three","class").qualified_class(@scope,"one").should == "one" + end + + it "should be able to find qualified classes when evaluating" do + klass = stub 'klass', :title => "one", :classname => "one" + @scope.stubs(:findclass).returns(klass) + + evaled = newref("one", "class").evaluate(@scope) + evaled.type.should == "Class" + evaled.title.should == "one" + end + + it "should return an array of reference if given an array of titles" do + titles = mock 'titles', :safeevaluate => ["title1","title2"] + ref = AST::ResourceReference.new( :title => titles, :type => "Resource" ) + ref.stubs(:qualified_type).with(@scope).returns("Resource") + + ref.evaluate(@scope).should have(2).elements + end + + it "should qualify class of all titles for Class resource references" do + titles = mock 'titles', :safeevaluate => ["title1","title2"] + ref = AST::ResourceReference.new( :title => titles, :type => "Class" ) + ref.expects(:qualified_class).with(@scope,"title1").returns("class") + ref.expects(:qualified_class).with(@scope,"title2").returns("class") + + ref.evaluate(@scope) + end + +end
\ No newline at end of file |
