delete_regex_spec.rb 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'spec_helper'
  2. describe 'delete_regex' do
  3. it { is_expected.not_to eq(nil) }
  4. it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
  5. it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError) }
  6. it { is_expected.to run.with_params([], 'two') }
  7. it { is_expected.to run.with_params({}, 'two') }
  8. it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError) }
  9. it { is_expected.to run.with_params([], 'two', 'three', 'four').and_raise_error(Puppet::ParseError) }
  10. it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
  11. describe 'deleting from an array' do
  12. it { is_expected.to run.with_params([], '').and_return([]) }
  13. it { is_expected.to run.with_params([], 'two').and_return([]) }
  14. it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
  15. it { is_expected.to run.with_params(%w[two two], 'two').and_return([]) }
  16. it { is_expected.to run.with_params(%w[one two three], '^t.*').and_return(['one']) }
  17. it { is_expected.to run.with_params(%w[ab b c b], 'b').and_return(%w[ab c]) }
  18. it { is_expected.to run.with_params(%w[one two three], 'four').and_return(%w[one two three]) }
  19. it { is_expected.to run.with_params(%w[one two three], 'e').and_return(%w[one two three]) }
  20. it { is_expected.to run.with_params(%w[one two three], 'two').and_return(%w[one three]) }
  21. it { is_expected.to run.with_params(%w[two one two three two], 'two').and_return(%w[one three]) }
  22. it { is_expected.to run.with_params(['abracadabra'], 'abr').and_return(['abracadabra']) }
  23. it { is_expected.to run.with_params(['abracadabra'], '^.*jimbob.*$').and_return(['abracadabra']) }
  24. end
  25. describe 'deleting from an array' do
  26. it { is_expected.to run.with_params({}, '').and_return({}) }
  27. it { is_expected.to run.with_params({}, 'key').and_return({}) }
  28. it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
  29. it {
  30. is_expected.to run \
  31. .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
  32. .and_return('key1' => 'value1', 'key3' => 'value3')
  33. }
  34. it {
  35. is_expected.to run \
  36. .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, %w[key1 key2]) \
  37. .and_return('key3' => 'value3')
  38. }
  39. end
  40. it 'leaves the original array intact' do
  41. argument1 = %w[one two three]
  42. original1 = argument1.dup
  43. subject.call([argument1, 'two'])
  44. expect(argument1).to eq(original1)
  45. end
  46. it 'leaves the original hash intact' do
  47. argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
  48. original1 = argument1.dup
  49. subject.call([argument1, 'key2'])
  50. expect(argument1).to eq(original1)
  51. end
  52. end