|
2 | 2 |
|
3 | 3 | describe 'merge' do
|
4 | 4 | it { is_expected.not_to eq(nil) }
|
5 |
| - it { is_expected.to run.with_params({}, 'two').and_raise_error(ArgumentError, Regexp.new(Regexp.escape("rejected: parameter 'args' expects a value of type Undef, Hash, or String[0, 0], got String"))) } |
6 |
| - it { is_expected.to run.with_params({}, 1).and_raise_error(ArgumentError, %r{parameter 'args' expects a value of type Undef, Hash, or String, got Integer}) } |
7 |
| - it { is_expected.to run.with_params({ 'one' => 1, 'three' => { 'four' => 4 } }, 'two' => 'dos', 'three' => { 'five' => 5 }).and_return('one' => 1, 'three' => { 'five' => 5 }, 'two' => 'dos') } |
| 5 | + it { |
| 6 | + is_expected.to run \ |
| 7 | + .with_params({}, 'two') \ |
| 8 | + .and_raise_error( |
| 9 | + ArgumentError, \ |
| 10 | + Regexp.new(Regexp.escape("rejected: parameter 'args' expects a value of type Undef, Hash, or String[0, 0], got String")), |
| 11 | + ) |
| 12 | + } |
| 13 | + it { |
| 14 | + is_expected.to run \ |
| 15 | + .with_params({}, 1) \ |
| 16 | + .and_raise_error(ArgumentError, %r{parameter 'args' expects a value of type Undef, Hash, or String, got Integer}) |
| 17 | + } |
| 18 | + it { |
| 19 | + is_expected.to run \ |
| 20 | + .with_params({ 'one' => 1, 'three' => { 'four' => 4 } }, 'two' => 'dos', 'three' => { 'five' => 5 }) \ |
| 21 | + .and_return('one' => 1, 'three' => { 'five' => 5 }, 'two' => 'dos') |
| 22 | + } |
8 | 23 |
|
9 | 24 | it { is_expected.to run.with_params.and_return({}) }
|
10 | 25 | it { is_expected.to run.with_params({}).and_return({}) }
|
|
14 | 29 | describe 'should accept empty strings as puppet undef' do
|
15 | 30 | it { is_expected.to run.with_params({}, '').and_return({}) }
|
16 | 31 | end
|
| 32 | + |
17 | 33 | it { is_expected.to run.with_params({ 'key' => 'value' }, {}).and_return('key' => 'value') }
|
18 | 34 | it { is_expected.to run.with_params({}, 'key' => 'value').and_return('key' => 'value') }
|
19 | 35 | it { is_expected.to run.with_params({ 'key' => 'value1' }, 'key' => 'value2').and_return('key' => 'value2') }
|
|
23 | 39 | .and_return('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3')
|
24 | 40 | }
|
25 | 41 | describe 'should accept iterable and merge produced hashes' do
|
26 |
| - |
27 |
| - it { is_expected.to run \ |
28 |
| - .with_params([1,2,3]) \ |
29 |
| - .with_lambda {|hsh, val| { val => val } } \ |
30 |
| - .and_return({ 1 => 1, 2 => 2, 3 => 3 }) } |
31 |
| - |
32 |
| - it { is_expected.to run \ |
33 |
| - .with_params([1,2,3]) \ |
34 |
| - .with_lambda {|hsh, val| { val => val } unless val == 2} \ |
35 |
| - .and_return({ 1 => 1, 3 => 3 }) } |
36 |
| - |
37 |
| - it { is_expected.to run \ |
38 |
| - .with_params([1,2,3]) \ |
39 |
| - .with_lambda {|hsh, val| raise StopIteration.new if val == 3; { val => val } } \ |
40 |
| - .and_return({ 1 => 1, 2 => 2 }) } |
41 |
| - |
42 |
| - it { is_expected.to run \ |
43 |
| - .with_params(['a', 'b', 'b', 'c', 'b']) \ |
44 |
| - .with_lambda {|hsh, val| { val => (hsh[val] || 0) + 1 } } \ |
45 |
| - .and_return({ 'a' => 1, 'b' => 3, 'c' => 1 }) } |
46 |
| - |
47 |
| - it { is_expected.to run \ |
48 |
| - .with_params(['a', 'b', 'c']) \ |
49 |
| - .with_lambda {|hsh, idx, val| { idx => val } } \ |
50 |
| - .and_return({ 0 => 'a', 1 => 'b', 2 => 'c'}) } |
51 |
| - |
52 |
| - it { is_expected.to run \ |
53 |
| - .with_params({'a' => 'A', 'b' => 'B', 'c' => 'C'}) \ |
54 |
| - .with_lambda {|hsh, key, val| { key => "#{key}#{val}" } } \ |
55 |
| - .and_return({ 'a' => 'aA', 'b' => 'bB', 'c' => 'cC'}) } |
56 |
| - |
| 42 | + it { |
| 43 | + is_expected.to run \ |
| 44 | + .with_params([1, 2, 3]) \ |
| 45 | + .with_lambda { |_hsh, val| { val => val } } \ |
| 46 | + .and_return(1 => 1, 2 => 2, 3 => 3) |
| 47 | + } |
| 48 | + it { |
| 49 | + is_expected.to run \ |
| 50 | + .with_params([1, 2, 3]) \ |
| 51 | + .with_lambda { |_hsh, val| { val => val } unless val == 2 } \ |
| 52 | + .and_return(1 => 1, 3 => 3) |
| 53 | + } |
| 54 | + it { |
| 55 | + is_expected.to run \ |
| 56 | + .with_params([1, 2, 3]) \ |
| 57 | + # rubocop:disable Style/Semicolon |
| 58 | + .with_lambda { |_hsh, val| raise StopIteration if val == 3; { val => val } } \ |
| 59 | + .and_return(1 => 1, 2 => 2) |
| 60 | + } |
| 61 | + it { |
| 62 | + is_expected.to run \ |
| 63 | + .with_params(['a', 'b', 'b', 'c', 'b']) \ |
| 64 | + .with_lambda { |hsh, val| { val => (hsh[val] || 0) + 1 } } \ |
| 65 | + .and_return('a' => 1, 'b' => 3, 'c' => 1) |
| 66 | + } |
| 67 | + it { |
| 68 | + is_expected.to run \ |
| 69 | + .with_params(['a', 'b', 'c']) \ |
| 70 | + .with_lambda { |_hsh, idx, val| { idx => val } } \ |
| 71 | + .and_return(0 => 'a', 1 => 'b', 2 => 'c') |
| 72 | + } |
| 73 | + it { |
| 74 | + is_expected.to run \ |
| 75 | + .with_params('a' => 'A', 'b' => 'B', 'c' => 'C') \ |
| 76 | + .with_lambda { |_hsh, key, val| { key => "#{key}#{val}" } } \ |
| 77 | + .and_return('a' => 'aA', 'b' => 'bB', 'c' => 'cC') |
| 78 | + } |
57 | 79 | end
|
58 | 80 | end
|
0 commit comments