source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/spec/functions/private_spec.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 2.0 KB
Line 
1require 'spec_helper'
2
3describe 'private' do
4 it 'should issue a warning' do
5 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.")
6 begin
7 subject.call []
8 rescue
9 # ignore this
10 end
11 end
12
13 context "when called from inside module" do
14 it "should not fail" do
15 scope.expects(:lookupvar).with('module_name').returns('foo')
16 scope.expects(:lookupvar).with('caller_module_name').returns('foo')
17 expect {
18 subject.call []
19 }.not_to raise_error
20 end
21 end
22
23 context "with an explicit failure message" do
24 it "prints the failure message on error" do
25 scope.expects(:lookupvar).with('module_name').returns('foo')
26 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
27 expect {
28 subject.call ['failure message!']
29 }.to raise_error Puppet::ParseError, /failure message!/
30 end
31 end
32
33 context "when called from private class" do
34 it "should fail with a class error message" do
35 scope.expects(:lookupvar).with('module_name').returns('foo')
36 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
37 scope.source.expects(:name).returns('foo::baz')
38 scope.source.expects(:type).returns('hostclass')
39 expect {
40 subject.call []
41 }.to raise_error Puppet::ParseError, /Class foo::baz is private/
42 end
43 end
44
45 context "when called from private definition" do
46 it "should fail with a class error message" do
47 scope.expects(:lookupvar).with('module_name').returns('foo')
48 scope.expects(:lookupvar).with('caller_module_name').returns('bar')
49 scope.source.expects(:name).returns('foo::baz')
50 scope.source.expects(:type).returns('definition')
51 expect {
52 subject.call []
53 }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
54 end
55 end
56end
Note: See TracBrowser for help on using the repository browser.