1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:private) do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 function_name = Puppet::Parser::Functions.function(:private)
9 scope.method(function_name)
12 it 'should issue a warning' do
13 scope.expects(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.")
17 context "when called from inside module" do
18 it "should not fail" do
19 scope.expects(:lookupvar).with('module_name').returns('foo')
20 scope.expects(:lookupvar).with('caller_module_name').returns('foo')
27 context "with an explicit failure message" do
28 it "prints the failure message on error" do
29 scope.expects(:lookupvar).with('module_name').returns('foo')
30 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
32 subject.call ['failure message!']
33 }.to raise_error Puppet::ParseError, /failure message!/
37 context "when called from private class" do
38 it "should fail with a class error message" do
39 scope.expects(:lookupvar).with('module_name').returns('foo')
40 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
41 scope.source.expects(:name).returns('foo::baz')
42 scope.source.expects(:type).returns('hostclass')
45 }.to raise_error Puppet::ParseError, /Class foo::baz is private/
49 context "when called from private definition" do
50 it "should fail with a class error message" do
51 scope.expects(:lookupvar).with('module_name').returns('foo')
52 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
53 scope.source.expects(:name).returns('foo::baz')
54 scope.source.expects(:type).returns('definition')
57 }.to raise_error Puppet::ParseError, /Definition foo::baz is private/