|
1 | 1 | require 'spec_helper_acceptance' |
| 2 | +require 'pry' |
2 | 3 |
|
3 | 4 | tmpdir = default.tmpdir('tmp') |
4 | 5 |
|
5 | 6 | describe 'ini_setting resource' do |
6 | 7 | after :all do |
7 | | - shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0,1,2]) |
| 8 | + shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2]) |
8 | 9 | end |
9 | 10 |
|
10 | | - shared_examples 'has_content' do |path,pp,content| |
| 11 | + shared_examples 'has_content' do |path, pp, content| |
11 | 12 | before :all do |
12 | | - shell("rm #{path}", :acceptable_exit_codes => [0,1,2]) |
| 13 | + shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2]) |
13 | 14 | end |
14 | 15 | after :all do |
15 | | - shell("cat #{path}", :acceptable_exit_codes => [0,1,2]) |
16 | | - shell("rm #{path}", :acceptable_exit_codes => [0,1,2]) |
| 16 | + shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2]) |
| 17 | + shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2]) |
17 | 18 | end |
18 | 19 |
|
19 | 20 | it 'applies the manifest twice' do |
|
23 | 24 |
|
24 | 25 | describe file(path) do |
25 | 26 | it { should be_file } |
26 | | - #XXX Solaris 10 doesn't support multi-line grep |
27 | | - it("should contain #{content}", :unless => fact('osfamily') == 'Solaris') { |
28 | | - should contain(content) |
29 | | - } |
| 27 | + its(:content) { should match content } |
30 | 28 | end |
31 | 29 | end |
32 | 30 |
|
33 | | - shared_examples 'has_error' do |path,pp,error| |
| 31 | + shared_examples 'has_error' do |path, pp, error| |
34 | 32 | before :all do |
35 | | - shell("rm #{path}", :acceptable_exit_codes => [0,1,2]) |
| 33 | + shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2]) |
36 | 34 | end |
37 | 35 | after :all do |
38 | | - shell("cat #{path}", :acceptable_exit_codes => [0,1,2]) |
39 | | - shell("rm #{path}", :acceptable_exit_codes => [0,1,2]) |
| 36 | + shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2]) |
| 37 | + shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2]) |
40 | 38 | end |
41 | 39 |
|
42 | 40 | it 'applies the manifest and gets a failure message' do |
|
72 | 70 | apply_manifest(pp, :catch_changes => true) |
73 | 71 | end |
74 | 72 |
|
75 | | - it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, "four = five\n[one]\ntwo = three" |
| 73 | + it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/ |
76 | 74 | end |
77 | 75 |
|
78 | 76 | context '=> absent for key/value' do |
79 | 77 | before :all do |
80 | 78 | if fact('osfamily') == 'Darwin' |
81 | | - shell("echo \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini") |
| 79 | + shell("echo \"four = five[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini") |
82 | 80 | else |
83 | 81 | shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini") |
84 | 82 | end |
|
96 | 94 |
|
97 | 95 | it 'applies the manifest twice' do |
98 | 96 | apply_manifest(pp, :catch_failures => true) |
99 | | - apply_manifest(pp, :catch_changes => true) |
| 97 | + apply_manifest(pp, :catch_changes => true) |
100 | 98 | end |
101 | 99 |
|
102 | 100 | describe file("#{tmpdir}/ini_setting.ini") do |
103 | 101 | it { should be_file } |
104 | | - it { should contain('four = five') } |
105 | | - it { should contain('[one]') } |
106 | | - it { should_not contain('two = three') } |
| 102 | + its(:content) { |
| 103 | + should match /four = five/ |
| 104 | + should match /\[one\]/ |
| 105 | + should_not match /two = three/ |
| 106 | + } |
107 | 107 | end |
108 | 108 | end |
109 | 109 |
|
|
116 | 116 | end |
117 | 117 | end |
118 | 118 | after :all do |
119 | | - shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2]) |
120 | | - shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2]) |
| 119 | + shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2]) |
| 120 | + shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2]) |
121 | 121 | end |
122 | 122 |
|
123 | 123 | pp = <<-EOS |
|
132 | 132 |
|
133 | 133 | it 'applies the manifest twice' do |
134 | 134 | apply_manifest(pp, :catch_failures => true) |
135 | | - apply_manifest(pp, :catch_changes => true) |
| 135 | + apply_manifest(pp, :catch_changes => true) |
136 | 136 | end |
137 | 137 |
|
138 | 138 | describe file("#{tmpdir}/ini_setting.ini") do |
139 | 139 | it { should be_file } |
140 | | - it { should_not contain('four = five') } |
141 | | - it { should contain('[one]') } |
142 | | - it { should contain('two = three') } |
| 140 | + its(:content) { |
| 141 | + should_not match /four = five/ |
| 142 | + should match /\[one\]/ |
| 143 | + should match /two = three/ |
| 144 | + } |
143 | 145 | end |
144 | 146 | end |
145 | 147 | end |
146 | 148 |
|
147 | 149 | describe 'section, setting, value parameters' do |
148 | 150 | { |
149 | | - "section => 'test', setting => 'foo', value => 'bar'," => "[test]\nfoo = bar", |
150 | | - "section => 'more', setting => 'baz', value => 'quux'," => "[more]\nbaz = quux", |
151 | | - "section => '', setting => 'top', value => 'level'," => "top = level", |
| 151 | + "section => 'test', setting => 'foo', value => 'bar'," => /\[test\]\nfoo = bar/, |
| 152 | + "section => 'more', setting => 'baz', value => 'quux'," => /\[more\]\nbaz = quux/, |
| 153 | + "section => '', setting => 'top', value => 'level'," => /top = level/, |
152 | 154 | }.each do |parameter_list, content| |
153 | 155 | context parameter_list do |
154 | 156 | pp = <<-EOS |
|
164 | 166 | end |
165 | 167 |
|
166 | 168 | { |
167 | | - "section => 'test'," => /setting is a required.+value is a required/, |
168 | | - "setting => 'foo', value => 'bar'," => /section is a required/, |
169 | | - "section => 'test', setting => 'foo'," => /value is a required/, |
170 | | - "section => 'test', value => 'bar'," => /setting is a required/, |
171 | | - "value => 'bar'," => /section is a required.+setting is a required/, |
172 | | - "setting => 'foo'," => /section is a required.+value is a required/, |
| 169 | + "section => 'test'," => /setting is a required.+value is a required/, |
| 170 | + "setting => 'foo', value => 'bar'," => /section is a required/, |
| 171 | + "section => 'test', setting => 'foo'," => /value is a required/, |
| 172 | + "section => 'test', value => 'bar'," => /setting is a required/, |
| 173 | + "value => 'bar'," => /section is a required.+setting is a required/, |
| 174 | + "setting => 'foo'," => /section is a required.+value is a required/, |
173 | 175 | }.each do |parameter_list, error| |
174 | 176 | context parameter_list, :pending => 'no error checking yet' do |
175 | 177 | pp = <<-EOS |
|
187 | 189 |
|
188 | 190 | describe 'path parameter' do |
189 | 191 | [ |
190 | | - "#{tmpdir}/one.ini", |
191 | | - "#{tmpdir}/two.ini", |
192 | | - "#{tmpdir}/three.ini", |
| 192 | + "#{tmpdir}/one.ini", |
| 193 | + "#{tmpdir}/two.ini", |
| 194 | + "#{tmpdir}/three.ini", |
193 | 195 | ].each do |path| |
194 | 196 | context "path => #{path}" do |
195 | 197 | pp = <<-EOS |
|
202 | 204 | } |
203 | 205 | EOS |
204 | 206 |
|
205 | | - it_behaves_like 'has_content', path, pp, "[one]\ntwo = three" |
| 207 | + it_behaves_like 'has_content', path, pp, /\[one\]\ntwo = three/ |
206 | 208 | end |
207 | 209 | end |
208 | 210 |
|
|
223 | 225 |
|
224 | 226 | describe 'key_val_separator parameter' do |
225 | 227 | { |
226 | | - "" => "two = three", |
227 | | - "key_val_separator => '='," => "two=three", |
228 | | - "key_val_separator => ' = '," => "two = three", |
| 228 | + "" => /two = three/, |
| 229 | + "key_val_separator => '='," => /two=three/, |
| 230 | + "key_val_separator => ' = '," => /two = three/, |
229 | 231 | }.each do |parameter, content| |
230 | 232 | context "with \"#{parameter}\" makes \"#{content}\"" do |
231 | 233 | pp = <<-EOS |
|
0 commit comments