summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/parser.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-21 21:46:12 -0800
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitb7ea1806703df2976d5cd6fade5503c008332526 (patch)
tree6a329c514db4913daba718235b181a75e4087aab /spec/unit/parser/parser.rb
parentcbe2c49c8ef2fc53664461947919958be0a0631c (diff)
downloadpuppet-b7ea1806703df2976d5cd6fade5503c008332526.tar.gz
puppet-b7ea1806703df2976d5cd6fade5503c008332526.tar.xz
puppet-b7ea1806703df2976d5cd6fade5503c008332526.zip
Partially fixing #2954 - Adding class parameters
This isn't 100% functional yet - I need to refactor some of the internals to make the class lookup work everywhere. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec/unit/parser/parser.rb')
-rwxr-xr-xspec/unit/parser/parser.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index bb0fa0a7b..84749c3fb 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -411,4 +411,45 @@ describe Puppet::Parser do
@parser.load("").should == false
end
end
+
+ describe "when parsing classes" do
+ before :each do
+ @krt = Puppet::Resource::TypeCollection.new("development")
+ @parser = Puppet::Parser::Parser.new "development"
+ @parser.stubs(:known_resource_types).returns @krt
+ end
+
+ it "should create new classes" do
+ @parser.parse("class foobar {}")
+ @krt.hostclass("foobar").should be_instance_of(Puppet::Resource::Type)
+ end
+
+ it "should correctly set the parent class when one is provided" do
+ @parser.parse("class foobar inherits yayness {}")
+ @krt.hostclass("foobar").parent.should == "yayness"
+ end
+
+ it "should define the code when some is provided" do
+ @parser.parse("class foobar { $var = val }")
+ @krt.hostclass("foobar").code.should_not be_nil
+ end
+
+ it "should define parameters when provided" do
+ @parser.parse("class foobar($biz,$baz) {}")
+ @krt.hostclass("foobar").arguments.should == {"biz" => nil, "baz" => nil}
+ end
+ end
+
+ describe "when parsing resources" do
+ before :each do
+ @krt = Puppet::Resource::TypeCollection.new("development")
+ @parser = Puppet::Parser::Parser.new "development"
+ @parser.stubs(:known_resource_types).returns @krt
+ end
+
+ it "should be able to parse class resources" do
+ @krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil}))
+ lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error
+ end
+ end
end