delete_spec.rb 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. require 'spec_helper'
  2. describe 'delete' 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', 'three').and_raise_error(Puppet::ParseError) }
  8. it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError) }
  9. describe 'deleting from an array' do
  10. it { is_expected.to run.with_params([], '').and_return([]) }
  11. it { is_expected.to run.with_params([], 'two').and_return([]) }
  12. it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
  13. it { is_expected.to run.with_params(%w[two two], 'two').and_return([]) }
  14. it { is_expected.to run.with_params(%w[ab b c b], 'b').and_return(%w[ab c]) }
  15. it { is_expected.to run.with_params(%w[one two three], 'four').and_return(%w[one two three]) }
  16. it { is_expected.to run.with_params(%w[one two three], 'e').and_return(%w[one two three]) }
  17. it { is_expected.to run.with_params(%w[one two three], 'two').and_return(%w[one three]) }
  18. it { is_expected.to run.with_params(%w[two one two three two], 'two').and_return(%w[one three]) }
  19. it { is_expected.to run.with_params(%w[one two three two], %w[one two]).and_return(['three']) }
  20. it { is_expected.to run.with_params(['ồאּẻ', 'ŧẅơ', 'ŧңŗё℮', 'ŧẅơ'], %w[ồאּẻ ŧẅơ]).and_return(['ŧңŗё℮']) }
  21. end
  22. describe 'deleting from a string' do
  23. it { is_expected.to run.with_params('', '').and_return('') }
  24. it { is_expected.to run.with_params('bar', '').and_return('bar') }
  25. it { is_expected.to run.with_params('', 'bar').and_return('') }
  26. it { is_expected.to run.with_params('bar', 'bar').and_return('') }
  27. it { is_expected.to run.with_params('barbar', 'bar').and_return('') }
  28. it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') }
  29. it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') }
  30. it { is_expected.to run.with_params('foobarbabarz', %w[foo bar]).and_return('baz') }
  31. it { is_expected.to run.with_params('ƒōōβậяβậβậяź', %w[ƒōō βậя]).and_return('βậź') }
  32. it { is_expected.to run.with_params('barfoobar', %w[barbar foo]).and_return('barbar') }
  33. it { is_expected.to run.with_params('barfoobar', %w[foo barbar]).and_return('') }
  34. end
  35. describe 'deleting from an array' do
  36. it { is_expected.to run.with_params({}, '').and_return({}) }
  37. it { is_expected.to run.with_params({}, 'key').and_return({}) }
  38. it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
  39. it {
  40. is_expected.to run \
  41. .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
  42. .and_return('key1' => 'value1', 'key3' => 'value3')
  43. }
  44. it {
  45. is_expected.to run \
  46. .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, %w[key1 key2]) \
  47. .and_return('key3' => 'value3')
  48. }
  49. it {
  50. is_expected.to run \
  51. .with_params({ 'ĸəұ1' => 'νãŀủĕ1', 'ĸəұ2' => 'νãŀủĕ2', 'ĸəұ3' => 'νãŀủĕ3' }, %w[ĸəұ1 ĸəұ2]) \
  52. .and_return('ĸəұ3' => 'νãŀủĕ3')
  53. }
  54. end
  55. it 'leaves the original array intact' do
  56. argument1 = %w[one two three]
  57. original1 = argument1.dup
  58. _result = subject.call([argument1, 'two'])
  59. expect(argument1).to eq(original1)
  60. end
  61. it 'leaves the original string intact' do
  62. argument1 = 'onetwothree'
  63. original1 = argument1.dup
  64. _result = subject.call([argument1, 'two'])
  65. expect(argument1).to eq(original1)
  66. end
  67. it 'leaves the original hash intact' do
  68. argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
  69. original1 = argument1.dup
  70. _result = subject.call([argument1, 'key2'])
  71. expect(argument1).to eq(original1)
  72. end
  73. end