3 describe Puppet::Type.type(:concat_fragment) do
5 described_class.new(name: 'foo', target: 'bar', content: 'baz')
8 describe 'key attributes' do
9 let(:subject) { described_class.key_attributes }
11 it 'contain only :name' do
12 is_expected.to eq([:name])
16 describe 'parameter :target' do
17 it_behaves_like 'a parameter that accepts only string values', :target
20 describe 'parameter :content' do
21 it_behaves_like 'a parameter that accepts only string values', :content
24 describe 'parameter :source' do
25 it 'accepts a string value' do
26 resource[:source] = 'foo'
27 expect(resource[:source]).to eq('foo')
30 it 'accepts an array value' do
31 resource[:source] = ['foo', 'bar']
32 expect(resource[:source]).to eq(['foo', 'bar'])
35 it 'does not accept a hash value' do
36 expect { resource[:source] = { foo: 'bar' } }.to raise_error(%r{must be a String or Array})
39 it 'does not accept an integer value' do
40 expect { resource[:source] = 9001 }.to raise_error(%r{must be a String or Array})
43 it 'does not accept a boolean true value' do
44 expect { resource[:source] = true }.to raise_error(%r{must be a String or Array})
47 it 'does not accept a boolean false value' do
48 expect { resource[:source] = false }.to raise_error(%r{must be a String or Array})
52 describe 'parameter :order' do
53 it 'accepts a string value' do
54 resource[:order] = 'foo'
55 expect(resource[:order]).to eq('foo')
58 it 'accepts an integer value' do
59 resource[:order] = 9001
60 expect(resource[:order]).to eq(9001)
63 it 'does not accept an array value' do
64 expect { resource[:order] = ['foo', 'bar'] }.to raise_error(%r{is not a string or integer})
67 it 'does not accept a hash value' do
68 expect { resource[:order] = { foo: 'bar' } }.to raise_error(%r{is not a string or integer})
71 it 'does not accept a boolean true value' do
72 expect { resource[:order] = true }.to raise_error(%r{is not a string or integer})
75 it 'does not accept a boolean false value' do
76 expect { resource[:order] = false }.to raise_error(%r{is not a string or integer})
79 it 'does not accept a string with ":" in it/' do
80 expect { resource[:order] = ':foo' }.to raise_error(%r{Order cannot contain})
83 it 'does not accept a string with "\n" in it/' do
84 expect { resource[:order] = "\nfoo" }.to raise_error(%r{Order cannot contain})
87 it 'does not accept a string with "/" in it/' do
88 expect { resource[:order] = '/foo' }.to raise_error(%r{Order cannot contain})
92 context 'without a value set for :target or :tag' do
93 it 'throws an error' do
94 expect { described_class.new(name: 'foo', content: 'baz') }.to raise_error(%r{No 'target' or 'tag' set})
98 context 'without a value set for both :content and :source' do
99 it 'throws an error' do
100 expect { described_class.new(name: 'foo', target: 'bar') }.to raise_error(%r{Set either 'source' or 'content'})
104 context 'with a value set for both :content and :source' do
105 it 'throws an error' do
107 described_class.new(name: 'foo', target: 'bar', content: 'baz', source: 'qux')
108 }.to raise_error(%r{Can't use 'source' and 'content' at the same time})