Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / spec / unit / type / concat_fragment_spec.rb
1 require 'spec_helper'
2
3 describe Puppet::Type.type(:concat_fragment) do
4   let(:resource) do
5     described_class.new(name: 'foo', target: 'bar', content: 'baz')
6   end
7
8   describe 'key attributes' do
9     let(:subject) { described_class.key_attributes }
10
11     it 'contain only :name' do
12       is_expected.to eq([:name])
13     end
14   end
15
16   describe 'parameter :target' do
17     it_behaves_like 'a parameter that accepts only string values', :target
18   end
19
20   describe 'parameter :content' do
21     it_behaves_like 'a parameter that accepts only string values', :content
22   end
23
24   describe 'parameter :source' do
25     it 'accepts a string value' do
26       resource[:source] = 'foo'
27       expect(resource[:source]).to eq('foo')
28     end
29
30     it 'accepts an array value' do
31       resource[:source] = ['foo', 'bar']
32       expect(resource[:source]).to eq(['foo', 'bar'])
33     end
34
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})
37     end
38
39     it 'does not accept an integer value' do
40       expect { resource[:source] = 9001 }.to raise_error(%r{must be a String or Array})
41     end
42
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})
45     end
46
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})
49     end
50   end
51
52   describe 'parameter :order' do
53     it 'accepts a string value' do
54       resource[:order] = 'foo'
55       expect(resource[:order]).to eq('foo')
56     end
57
58     it 'accepts an integer value' do
59       resource[:order] = 9001
60       expect(resource[:order]).to eq(9001)
61     end
62
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})
65     end
66
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})
69     end
70
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})
73     end
74
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})
77     end
78
79     it 'does not accept a string with ":" in it/' do
80       expect { resource[:order] = ':foo' }.to raise_error(%r{Order cannot contain})
81     end
82
83     it 'does not accept a string with "\n" in it/' do
84       expect { resource[:order] = "\nfoo" }.to raise_error(%r{Order cannot contain})
85     end
86
87     it 'does not accept a string with "/" in it/' do
88       expect { resource[:order] = '/foo' }.to raise_error(%r{Order cannot contain})
89     end
90   end
91
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})
95     end
96   end
97
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'})
101     end
102   end
103
104   context 'with a value set for both :content and :source' do
105     it 'throws an error' do
106       expect {
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})
109     end
110   end
111 end