1 require 'spec_helper_acceptance'
3 describe 'format of file' do
5 @basedir = setup_test_directory
8 describe 'when run should default to plain' do
11 concat { '#{@basedir}/file':
14 concat::fragment { '1':
15 target => '#{@basedir}/file',
16 content => '{"one": "foo"}',
19 concat::fragment { '2':
20 target => '#{@basedir}/file',
21 content => '{"one": "bar"}',
26 it 'idempotent, file matches' do
28 expect(file("#{@basedir}/file")).to be_file
29 expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'
33 describe 'when run should output to plain format' do
36 concat { '#{@basedir}/file':
40 concat::fragment { '1':
41 target => '#{@basedir}/file',
42 content => '{"one": "foo"}',
45 concat::fragment { '2':
46 target => '#{@basedir}/file',
47 content => '{"one": "bar"}',
52 it 'idempotent, file matches' do
54 expect(file("#{@basedir}/file")).to be_file
55 expect(file("#{@basedir}/file").content).to match '{"one": "foo"}{"one": "bar"}'
59 describe 'when run should output to yaml format' do
62 concat { '#{@basedir}/file':
66 concat::fragment { '1':
67 target => '#{@basedir}/file',
68 content => '{"one": "foo"}',
71 concat::fragment { '2':
72 target => '#{@basedir}/file',
73 content => '{"two": "bar"}',
78 it 'idempotent, file matches' do
80 expect(file("#{@basedir}/file")).to be_file
81 expect(file("#{@basedir}/file").content).to match 'one: foo\Rtwo: bar'
85 describe 'when run should output yaml arrays to yaml format' do
88 concat { '#{@basedir}/file':
92 concat::fragment { '1':
93 target => '#{@basedir}/file',
94 content => to_yaml([{ 'one.a' => 'foo', 'one.b' => 'bar' }]),
97 concat::fragment { '2':
98 target => '#{@basedir}/file',
99 content => to_yaml([{ 'two.a' => 'dip', 'two.b' => 'doot' }]),
104 it 'idempotent, file matches' do
106 expect(file("#{@basedir}/file")).to be_file
107 expect(file("#{@basedir}/file").content).to match '- one.a: foo\R one.b: bar\R- two.a: dip\R two.b: doot'
111 describe 'when run should output to json format' do
114 concat { '#{@basedir}/file':
118 concat::fragment { '1':
119 target => '#{@basedir}/file',
120 content => '{"one": "foo"}',
123 concat::fragment { '2':
124 target => '#{@basedir}/file',
125 content => '{"two": "bar"}',
130 it 'idempotent, file matches' do
132 expect(file("#{@basedir}/file")).to be_file
133 expect(file("#{@basedir}/file").content).to match '{"one":"foo","two":"bar"}'
137 describe 'when run should output to json-array format' do
140 concat { '#{@basedir}/file':
141 format => 'json-array',
144 concat::fragment { '1':
145 target => '#{@basedir}/file',
146 content => '{"one": "foo"}',
149 concat::fragment { '2':
150 target => '#{@basedir}/file',
151 content => '{"two": "bar"}',
156 it 'idempotent, file matches' do
158 expect(file("#{@basedir}/file")).to be_file
159 expect(file("#{@basedir}/file").content).to match '[{"one":"foo"},{"two":"bar"}]'
163 describe 'when run should output to json-pretty format' do
166 concat { '#{@basedir}/file':
167 format => 'json-pretty',
170 concat::fragment { '1':
171 target => '#{@basedir}/file',
172 content => '{"one": "foo"}',
175 concat::fragment { '2':
176 target => '#{@basedir}/file',
177 content => '{"two": "bar"}',
182 it 'idempotent, file matches' do
184 expect(file("#{@basedir}/file")).to be_file
185 expect(file("#{@basedir}/file").content).to match '{\R "one": "foo",\R "two": "bar"\R}'
189 describe 'when run should output to json-array-pretty format' do
192 concat { '#{@basedir}/file':
193 format => 'json-array-pretty',
196 concat::fragment { '1':
197 target => '#{@basedir}/file',
198 content => '{"one": "foo"}',
201 concat::fragment { '2':
202 target => '#{@basedir}/file',
203 content => '{"two": "bar"}',
208 it 'idempotent, file matches' do
210 expect(file("#{@basedir}/file")).to be_file
211 expect(file("#{@basedir}/file").content).to match '[\n {\n "one": "foo"\n },\n {\n "two": "bar"\n }\n]'