]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/private_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / private_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:private) do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   subject do
8     function_name = Puppet::Parser::Functions.function(:private)
9     scope.method(function_name)
10   end
11
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.")
14     subject.call []
15   end
16
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')
21       expect {
22         subject.call []
23       }.not_to raise_error
24     end
25   end
26
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')
31       expect {
32         subject.call ['failure message!']
33       }.to raise_error Puppet::ParseError, /failure message!/
34     end
35   end
36
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')
43       expect {
44         subject.call []
45       }.to raise_error Puppet::ParseError, /Class foo::baz is private/
46     end
47   end
48
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')
55       expect {
56         subject.call []
57       }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
58     end
59   end
60 end