355e0dd3a17051b5a4ede5cda444021a835588bd
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / assert_private_spec.rb
1 require 'spec_helper'
2
3 describe 'assert_private' do
4   context 'when called from inside module' do
5     it "should not fail" do
6       scope.expects(:lookupvar).with('module_name').returns('foo')
7       scope.expects(:lookupvar).with('caller_module_name').returns('foo')
8
9       is_expected.to run.with_params()
10     end
11   end
12
13   context "when called from private class" do
14     before :each do
15       scope.expects(:lookupvar).with('module_name').returns('foo')
16       scope.expects(:lookupvar).with('caller_module_name').returns('bar')
17     end
18
19     it "should fail with a class error message" do
20       scope.source.expects(:name).returns('foo::baz')
21       scope.source.expects(:type).returns('hostclass')
22
23       is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Class foo::baz is private/)
24     end
25
26     context "with an explicit failure message" do
27       it { is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, /failure message!/) }
28     end
29   end
30
31   context "when called from private definition" do
32     it "should fail with a class error message" do
33       scope.expects(:lookupvar).with('module_name').returns('foo')
34       scope.expects(:lookupvar).with('caller_module_name').returns('bar')
35       scope.source.expects(:name).returns('foo::baz')
36       scope.source.expects(:type).returns('definition')
37
38       is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Definition foo::baz is private/)
39     end
40   end
41 end