diff options
author | Stig Sandbeck Mathisen <ssm@debian.org> | 2014-09-07 10:14:36 +0200 |
---|---|---|
committer | Stig Sandbeck Mathisen <ssm@debian.org> | 2014-09-07 10:14:36 +0200 |
commit | d4b83be375ac1dead058e091191ee7c7b7c24c8a (patch) | |
tree | dc825687392ae3068de5b764be60c53122d9e02a /spec/unit/parser/functions/shared.rb | |
parent | 229cbb976fe0f70f5f30548b83517b415840f9bb (diff) | |
parent | 1681684857c6e39d60d87b0b3520d8783977ceff (diff) | |
download | puppet-upstream/3.7.0.tar.gz |
Imported Upstream version 3.7.0upstream/3.7.0
Diffstat (limited to 'spec/unit/parser/functions/shared.rb')
-rw-r--r-- | spec/unit/parser/functions/shared.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/shared.rb b/spec/unit/parser/functions/shared.rb new file mode 100644 index 000000000..f5adcd811 --- /dev/null +++ b/spec/unit/parser/functions/shared.rb @@ -0,0 +1,82 @@ +shared_examples_for 'all functions transforming relative to absolute names' do |func_method| + + it 'transforms relative names to absolute' do + @scope.compiler.expects(:evaluate_classes).with(["::myclass"], @scope, false) + @scope.send(func_method, ["myclass"]) + end + + it 'accepts a Class[name] type' do + @scope.compiler.expects(:evaluate_classes).with(["::myclass"], @scope, false) + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.host_class('myclass')]) + end + + it 'accepts a Resource[class, name] type' do + @scope.compiler.expects(:evaluate_classes).with(["::myclass"], @scope, false) + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.resource('class', 'myclass')]) + end + + it 'raises and error for unspecific Class' do + expect { + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.host_class()]) + }.to raise_error(ArgumentError, /Cannot use an unspecific Class\[\] Type/) + end + + it 'raises and error for Resource that is not of class type' do + expect { + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.resource('file')]) + }.to raise_error(ArgumentError, /Cannot use a Resource\[file\] where a Resource\['class', name\] is expected/) + end + + it 'raises and error for Resource that is unspecific' do + expect { + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.resource()]) + }.to raise_error(ArgumentError, /Cannot use an unspecific Resource\[\] where a Resource\['class', name\] is expected/) + end + + it 'raises and error for Resource[class] that is unspecific' do + expect { + @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.resource('class')]) + }.to raise_error(ArgumentError, /Cannot use an unspecific Resource\['class'\] where a Resource\['class', name\] is expected/) + end + +end + +shared_examples_for 'an inclusion function, regardless of the type of class reference,' do |function| + + it "and #{function} a class absolutely, even when a relative namespaced class of the same name is present" do + catalog = compile_to_catalog(<<-MANIFEST) + class foo { + class bar { } + #{function} bar + } + class bar { } + include foo + MANIFEST + expect(catalog.classes).to include('foo','bar') + end + + it "and #{function} a class absolutely by Class['type'] reference" do + catalog = compile_to_catalog(<<-MANIFEST) + class foo { + class bar { } + #{function} Class['bar'] + } + class bar { } + include foo + MANIFEST + expect(catalog.classes).to include('foo','bar') + end + + it "and #{function} a class absolutely by Resource['type','title'] reference" do + catalog = compile_to_catalog(<<-MANIFEST) + class foo { + class bar { } + #{function} Resource['class','bar'] + } + class bar { } + include foo + MANIFEST + expect(catalog.classes).to include('foo','bar') + end + +end |