]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/assert_private_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / assert_private_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe Puppet::Parser::Functions.function(:assert_private) do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   subject do
8     function_name = Puppet::Parser::Functions.function(:assert_private)
9     scope.method(function_name)
10   end
11
12   context "when called from inside module" do
13     it "should not fail" do
14       scope.expects(:lookupvar).with('module_name').returns('foo')
15       scope.expects(:lookupvar).with('caller_module_name').returns('foo')
16       expect {
17         subject.call []
18       }.not_to raise_error
19     end
20   end
21
22   context "with an explicit failure message" do
23     it "prints the failure message on error" do
24       scope.expects(:lookupvar).with('module_name').returns('foo')
25       scope.expects(:lookupvar).with('caller_module_name').returns('bar')
26       expect {
27         subject.call ['failure message!']
28       }.to raise_error Puppet::ParseError, /failure message!/
29     end
30   end
31
32   context "when called from private class" do
33     it "should fail with a class error message" do
34       scope.expects(:lookupvar).with('module_name').returns('foo')
35       scope.expects(:lookupvar).with('caller_module_name').returns('bar')
36       scope.source.expects(:name).returns('foo::baz')
37       scope.source.expects(:type).returns('hostclass')
38       expect {
39         subject.call []
40       }.to raise_error Puppet::ParseError, /Class foo::baz is private/
41     end
42   end
43
44   context "when called from private definition" do
45     it "should fail with a class error message" do
46       scope.expects(:lookupvar).with('module_name').returns('foo')
47       scope.expects(:lookupvar).with('caller_module_name').returns('bar')
48       scope.source.expects(:name).returns('foo::baz')
49       scope.source.expects(:type).returns('definition')
50       expect {
51         subject.call []
52       }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
53     end
54   end
55 end