spec/unit/chef/sugar/node_spec.rb in chef-sugar-2.5.0 vs spec/unit/chef/sugar/node_spec.rb in chef-sugar-3.0.0
- old
+ new
@@ -45,11 +45,17 @@
end
it 'raises an error if a key does not exist' do
expect {
node.deep_fetch!(:apache2, :not_real)
- }.to raise_error(Chef::Node::AttributeDoesNotExistError)
+ }.to raise_error(Chef::Node::AttributeDoesNotExistError) { |e|
+ expect(e.message).to eq(<<-EOH.gsub(/^ {10}/, ''))
+ No attribute `node['apache2']['not_real']' exists on
+ the current node. Specifically the `not_real' attribute is not
+ defined. Please make sure you have spelled everything correctly.
+ EOH
+ }
end
end
describe '#namespace' do
let(:node) { described_class.new }
@@ -94,9 +100,51 @@
end
expect(node.override).to eq({
'apache2' => {
'config' => { 'root' => '/var/www' }
+ }
+ })
+ end
+
+ it 'maintains precedence level into nested calls' do
+ node.instance_eval do
+ namespace 'apache2', precedence: override do
+ namespace 'config' do
+ root '/var/www'
+ end
+ end
+ end
+
+ expect(node.override).to eq({
+ 'apache2' => {
+ 'config' => { 'root' => '/var/www' }
+ }
+ })
+ end
+
+ it 'resets precedence to default in subsequent non-nested calls' do
+ node.instance_eval do
+ namespace 'apache2', precedence: override do
+ namespace 'config' do
+ root '/var/www'
+ end
+ end
+
+ namespace 'php' do
+ version '5.3'
+ end
+ end
+
+ expect(node.override).to eq({
+ 'apache2' => {
+ 'config' => { 'root' => '/var/www' }
+ }
+ })
+
+ expect(node.default).to eq({
+ 'php' => {
+ 'version' => '5.3'
}
})
end
it 'can access attributes within itself' do