1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:assert_private) do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 function_name = Puppet::Parser::Functions.function(:assert_private)
9 scope.method(function_name)
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')
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')
27 subject.call ['failure message!']
28 }.to raise_error Puppet::ParseError, /failure message!/
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')
40 }.to raise_error Puppet::ParseError, /Class foo::baz is private/
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')
52 }.to raise_error Puppet::ParseError, /Definition foo::baz is private/