assert_private_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'spec_helper'
  2. describe 'assert_private' do
  3. context 'when called from inside module' do
  4. it 'does not fail' do
  5. scope.expects(:lookupvar).with('module_name').returns('foo')
  6. scope.expects(:lookupvar).with('caller_module_name').returns('foo')
  7. is_expected.to run.with_params
  8. end
  9. end
  10. context 'when called from private class' do
  11. before :each do
  12. scope.expects(:lookupvar).with('module_name').returns('foo')
  13. scope.expects(:lookupvar).with('caller_module_name').returns('bar')
  14. end
  15. it 'fails with a class error message' do
  16. scope.source.expects(:name).returns('foo::baz')
  17. scope.source.expects(:type).returns('hostclass')
  18. is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Class foo::baz is private})
  19. end
  20. context 'with an explicit failure message' do
  21. it { is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, %r{failure message!}) }
  22. end
  23. end
  24. context 'when called from private definition' do
  25. it 'fails with a class error message' do
  26. scope.expects(:lookupvar).with('module_name').returns('foo')
  27. scope.expects(:lookupvar).with('caller_module_name').returns('bar')
  28. scope.source.expects(:name).returns('foo::baz')
  29. scope.source.expects(:type).returns('definition')
  30. is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Definition foo::baz is private})
  31. end
  32. end
  33. end