|
146 | 146 | end |
147 | 147 | end |
148 | 148 | end |
149 | | - # rubocop:enable RSpec/InstanceVariable : replacing before with let breaks the tests : multi |
150 | 149 | context 'when match+replace+append_on_no_match' do |
151 | 150 | pending('to do') |
152 | 151 | end |
|
181 | 180 | before :each do |
182 | 181 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nfoo = baz") } |
183 | 182 | end |
| 183 | + # rubocop:disable RSpec/NestedGroups : Reducing the nesting would needlesly complicate the code |
184 | 184 | describe 'inserts at match' do |
185 | 185 | include_context 'resource_create' |
186 | 186 | it { |
|
228 | 228 | end |
229 | 229 |
|
230 | 230 | it 'adds the line after all lines matching the after expression' do |
231 | | - @resource = Puppet::Type::File_line.new( |
232 | | - name: 'foo', |
233 | | - path: tmpfile, |
234 | | - line: 'inserted = line', |
235 | | - after: '^foo1$', |
236 | | - multiple: true, |
237 | | - ) |
| 231 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'inserted = line', after: '^foo1$', multiple: true) |
238 | 232 | @provider = provider_class.new(@resource) |
239 | | - expect(@provider.exists?).to be false |
240 | 233 | @provider.create |
241 | 234 | expect(File.read(tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo1\ninserted = line\nfoo = baz") |
242 | 235 | end |
|
285 | 278 | expect(File.read(tmpfile)).to eql("foo1\nfoo2\n") |
286 | 279 | end |
287 | 280 | it 'example in the docs' do |
288 | | - @resource = Puppet::Type::File_line.new( |
289 | | - name: 'bashrc_proxy', |
290 | | - ensure: 'absent', |
291 | | - path: tmpfile, |
292 | | - line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', |
293 | | - ) |
| 281 | + @resource = Puppet::Type::File_line.new(name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128') |
294 | 282 | @provider = provider_class.new(@resource) |
295 | 283 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=http://squid.puppetlabs.vm:3128\nfoo4\n") } |
296 | 284 | @provider.destroy |
|
322 | 310 | end |
323 | 311 |
|
324 | 312 | it 'the line parameter is actually not used at all but is silently ignored if here' do |
325 | | - @resource = Puppet::Type::File_line.new( |
326 | | - name: 'foo', |
327 | | - path: tmpfile, |
328 | | - line: 'supercalifragilisticexpialidocious', |
329 | | - ensure: 'absent', |
330 | | - match: 'o$', |
331 | | - match_for_absence: true, |
332 | | - ) |
| 313 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'supercalifragilisticexpialidocious', ensure: 'absent', match: 'o$', match_for_absence: true) |
333 | 314 | @provider = provider_class.new(@resource) |
334 | 315 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } |
335 | | - expect(@provider.exists?).to be true |
336 | 316 | @provider.destroy |
337 | 317 | expect(File.read(tmpfile)).to eql("foo1\nfoo2") |
338 | 318 | end |
339 | 319 |
|
340 | 320 | it 'and may not be here and does not need to be here' do |
341 | | - @resource = Puppet::Type::File_line.new( |
342 | | - name: 'foo', |
343 | | - path: tmpfile, |
344 | | - ensure: 'absent', |
345 | | - match: 'o$', |
346 | | - match_for_absence: true, |
347 | | - ) |
| 321 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, ensure: 'absent', match: 'o$', match_for_absence: true) |
348 | 322 | @provider = provider_class.new(@resource) |
349 | 323 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } |
350 | | - expect(@provider.exists?).to be true |
351 | 324 | @provider.destroy |
352 | 325 | expect(File.read(tmpfile)).to eql("foo1\nfoo2") |
353 | 326 | end |
|
358 | 331 | end |
359 | 332 |
|
360 | 333 | it 'removes multiple lines if :multiple is true' do |
361 | | - @resource = Puppet::Type::File_line.new( |
362 | | - name: 'foo', |
363 | | - path: tmpfile, |
364 | | - line: 'foo2', |
365 | | - ensure: 'absent', |
366 | | - match: 'o$', |
367 | | - multiple: true, |
368 | | - match_for_absence: true, |
369 | | - ) |
| 334 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$', multiple: true, match_for_absence: true) |
370 | 335 | @provider = provider_class.new(@resource) |
371 | 336 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2\nfoo\nfoo") } |
372 | | - expect(@provider.exists?).to be true |
373 | 337 | @provider.destroy |
374 | 338 | expect(File.read(tmpfile)).to eql("foo1\nfoo2\n") |
375 | 339 | end |
376 | 340 |
|
377 | 341 | it 'ignores the match if match_for_absence is not specified' do |
378 | | - @resource = Puppet::Type::File_line.new( |
379 | | - name: 'foo', |
380 | | - path: tmpfile, |
381 | | - line: 'foo2', |
382 | | - ensure: 'absent', |
383 | | - match: 'o$', |
384 | | - ) |
| 342 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$') |
385 | 343 | @provider = provider_class.new(@resource) |
386 | 344 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } |
387 | | - expect(@provider.exists?).to be true |
388 | 345 | @provider.destroy |
389 | 346 | expect(File.read(tmpfile)).to eql("foo1\nfoo\n") |
390 | 347 | end |
391 | 348 |
|
392 | 349 | it 'ignores the match if match_for_absence is false' do |
393 | | - @resource = Puppet::Type::File_line.new( |
394 | | - name: 'foo', |
395 | | - path: tmpfile, |
396 | | - line: 'foo2', |
397 | | - ensure: 'absent', |
398 | | - match: 'o$', |
399 | | - match_for_absence: false, |
400 | | - ) |
| 350 | + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$', match_for_absence: false) |
401 | 351 | @provider = provider_class.new(@resource) |
402 | 352 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } |
403 | | - expect(@provider.exists?).to be true |
404 | 353 | @provider.destroy |
405 | 354 | expect(File.read(tmpfile)).to eql("foo1\nfoo\n") |
406 | 355 | end |
407 | 356 |
|
408 | | - it 'example in the docs' do |
| 357 | + it 'example in the docs' do # rubocop:disable RSpec/ExampleLength : Cannot reduce without violating line length rule |
409 | 358 | @resource = Puppet::Type::File_line.new( |
410 | | - name: 'bashrc_proxy', |
411 | | - ensure: 'absent', |
412 | | - path: tmpfile, |
413 | | - line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', |
414 | | - match: '^export\ HTTP_PROXY\=', |
415 | | - match_for_absence: true, |
| 359 | + name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', |
| 360 | + match: '^export\ HTTP_PROXY\=', match_for_absence: true |
416 | 361 | ) |
417 | 362 | @provider = provider_class.new(@resource) |
418 | 363 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") } |
419 | | - expect(@provider.exists?).to be true |
420 | 364 | @provider.destroy |
421 | 365 | expect(File.read(tmpfile)).to eql("foo1\nfoo2\nfoo4\n") |
422 | 366 | end |
423 | 367 |
|
424 | 368 | it 'example in the docs showing line is redundant' do |
425 | | - @resource = Puppet::Type::File_line.new( |
426 | | - name: 'bashrc_proxy', |
427 | | - ensure: 'absent', |
428 | | - path: tmpfile, |
429 | | - match: '^export\ HTTP_PROXY\=', |
430 | | - match_for_absence: true, |
431 | | - ) |
| 369 | + @resource = Puppet::Type::File_line.new(name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, match: '^export\ HTTP_PROXY\=', match_for_absence: true) |
432 | 370 | @provider = provider_class.new(@resource) |
433 | 371 | File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") } |
434 | | - expect(@provider.exists?).to be true |
435 | 372 | @provider.destroy |
436 | 373 | expect(File.read(tmpfile)).to eql("foo1\nfoo2\nfoo4\n") |
437 | 374 | end |
438 | 375 | end |
| 376 | + # rubocop:enable RSpec/InstanceVariable : multi |
439 | 377 | end |
0 commit comments