|
24 | 24 | it "returns 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'" do
|
25 | 25 | allow(File).to receive(:exist?).and_call_original
|
26 | 26 | expect(File).to receive(:exist?).with(filename).and_return(true).once
|
27 |
| - expect(YAML).to receive(:load_file).with(filename).and_return(data).once |
| 27 | + expect(YAML).to receive(:load_file).with(filename, aliases: true).and_return(data).once |
28 | 28 | expect(subject).to run.with_params(filename).and_return(data)
|
29 | 29 | end
|
30 | 30 | end
|
|
35 | 35 | it 'filename /tmp/doesexist' do
|
36 | 36 | allow(File).to receive(:exist?).and_call_original
|
37 | 37 | expect(File).to receive(:exist?).with(filename).and_return(true).once
|
38 |
| - allow(YAML).to receive(:load_file).with(filename).once.and_raise(StandardError, 'Something terrible have happened!') |
| 38 | + allow(YAML).to receive(:load_file).with(filename, aliases: true).once.and_raise(StandardError, 'Something terrible have happened!') |
39 | 39 | expect(subject).to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
|
40 | 40 | end
|
41 | 41 | end
|
|
48 | 48 |
|
49 | 49 | it {
|
50 | 50 | expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml)
|
51 |
| - expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
| 51 | + expect(YAML).to receive(:safe_load).with(yaml, aliases: true).and_return(data).once |
52 | 52 | expect(subject).to run.with_params(filename).and_return(data)
|
53 | 53 | }
|
54 | 54 | end
|
|
62 | 62 |
|
63 | 63 | it {
|
64 | 64 | expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml)
|
65 |
| - expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
| 65 | + expect(YAML).to receive(:safe_load).with(yaml, aliases: true).and_return(data).once |
66 | 66 | expect(subject).to run.with_params(filename).and_return(data)
|
67 | 67 | }
|
68 | 68 | end
|
|
76 | 76 |
|
77 | 77 | it {
|
78 | 78 | expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(yaml)
|
79 |
| - expect(YAML).to receive(:safe_load).with(yaml).and_return(data).once |
| 79 | + expect(YAML).to receive(:safe_load).with(yaml, aliases: true).and_return(data).once |
80 | 80 | expect(subject).to run.with_params(filename).and_return(data)
|
81 | 81 | }
|
82 | 82 | end
|
|
88 | 88 |
|
89 | 89 | it {
|
90 | 90 | expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml)
|
91 |
| - expect(YAML).to receive(:safe_load).with(yaml).and_raise StandardError, 'Cannot parse data' |
| 91 | + expect(YAML).to receive(:safe_load).with(yaml, aliases: true).and_raise StandardError, 'Cannot parse data' |
92 | 92 | expect(subject).to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
|
93 | 93 | }
|
94 | 94 | end
|
|
103 | 103 | expect(subject).to run.with_params(filename, 'default' => 'value').and_return('default' => 'value')
|
104 | 104 | }
|
105 | 105 | end
|
| 106 | + |
| 107 | + context 'when the file contains aliases' do |
| 108 | + let(:tempfile) { Tempfile.new } |
| 109 | + let(:filename) { tempfile.path } |
| 110 | + let(:yaml) do |
| 111 | + <<~YAML |
| 112 | + some_numbers: &nums |
| 113 | + - one |
| 114 | + - two |
| 115 | + more_numbers: *nums |
| 116 | + YAML |
| 117 | + end |
| 118 | + let(:data) { { 'some_numbers' => ['one', 'two'], 'more_numbers' => ['one', 'two'] } } |
| 119 | + |
| 120 | + it 'parses the aliases' do |
| 121 | + tempfile.write(yaml) |
| 122 | + tempfile.rewind |
| 123 | + expect(subject).to run.with_params(filename).and_return(data) |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + context 'when an URL returns yaml with aliases' do |
| 128 | + let(:filename) { 'https://example.local/myhash.yaml' } |
| 129 | + let(:basic_auth) { { http_basic_authentication: ['', ''] } } |
| 130 | + let(:yaml) do |
| 131 | + <<~YAML |
| 132 | + some_numbers: &nums |
| 133 | + - one |
| 134 | + - two |
| 135 | + more_numbers: *nums |
| 136 | + YAML |
| 137 | + end |
| 138 | + let(:data) { { 'some_numbers' => ['one', 'two'], 'more_numbers' => ['one', 'two'] } } |
| 139 | + |
| 140 | + it { |
| 141 | + expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_return(yaml) |
| 142 | + expect(subject).to run.with_params(filename).and_return(data) |
| 143 | + } |
| 144 | + end |
106 | 145 | end
|
0 commit comments