4 it 'issues a warning' do
5 expect(scope).to receive(: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.") # rubocop:disable Metrics/LineLength : unable to cut line to required length
8 rescue # rubocop:disable Lint/HandleExceptions
13 context 'when called from inside module' do
15 expect(scope).to receive(:lookupvar).with('module_name').and_return('foo')
16 expect(scope).to receive(:lookupvar).with('caller_module_name').and_return('foo')
23 context 'with an explicit failure message' do
24 it 'prints the failure message on error' do
25 expect(scope).to receive(:lookupvar).with('module_name').and_return('foo')
26 expect(scope).to receive(:lookupvar).with('caller_module_name').and_return('bar')
28 subject.execute('failure message!')
29 }.to raise_error(Puppet::ParseError, %r{failure message!})
33 context 'when called from private class' do
34 it 'fails with a class error message' do
35 expect(scope).to receive(:lookupvar).with('module_name').and_return('foo')
36 expect(scope).to receive(:lookupvar).with('caller_module_name').and_return('bar')
37 expect(scope.source).to receive(:name).and_return('foo::baz')
38 expect(scope.source).to receive(:type).and_return('hostclass')
39 expect { subject.execute }.to raise_error(Puppet::ParseError, %r{Class foo::baz is private})
43 context 'when called from private definition' do
44 it 'fails with a class error message' do
45 expect(scope).to receive(:lookupvar).with('module_name').and_return('foo')
46 expect(scope).to receive(:lookupvar).with('caller_module_name').and_return('bar')
47 expect(scope.source).to receive(:name).and_return('foo::baz')
48 expect(scope.source).to receive(:type).and_return('definition')
49 expect { subject.execute }.to raise_error(Puppet::ParseError, %r{Definition foo::baz is private})