|
113 | 113 |
|
114 | 114 | context 'when insync? is not defined in the provider' do |
115 | 115 | it 'raises an error' do |
116 | | - expect(referrable_type_custom_insync).to receive(:my_provider).and_return(test_provider_without_insync) |
| 116 | + allow(referrable_type_custom_insync).to receive(:my_provider).and_return(test_provider_without_insync) |
| 117 | + expect(referrable_type_custom_insync).to receive(:my_provider) |
117 | 118 | expect { custom_insync_property.insync?('Foo') }.to raise_error Puppet::DevError, /No insync\? method defined in the provider/ |
118 | 119 | end |
119 | 120 | end |
|
159 | 160 |
|
160 | 161 | context 'when custom insync from the provider returns a boolean for the result' do |
161 | 162 | it 'returns true if the result was true' do |
162 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(true) |
| 163 | + allow(test_provider_with_insync).to receive(:insync?).and_return(true) |
| 164 | + expect(test_provider_with_insync).to receive(:insync?) |
163 | 165 | expect(custom_insync_property.insync?('Foo')).to be true |
164 | 166 | end |
165 | 167 |
|
166 | 168 | it 'returns false if result was false' do |
167 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(false) |
| 169 | + allow(test_provider_with_insync).to receive(:insync?).and_return(false) |
| 170 | + expect(test_provider_with_insync).to receive(:insync?) |
168 | 171 | expect(custom_insync_property.insync?('Foo')).to be false |
169 | 172 | end |
170 | 173 | end |
171 | 174 |
|
172 | 175 | context 'when custom insync from the provider returns a string for the result' do |
173 | 176 | it 'raises an explanatory DevError' do |
174 | | - expect(test_provider_with_insync).to receive(:insync?).and_return('true') |
| 177 | + allow(test_provider_with_insync).to receive(:insync?).and_return('true') |
| 178 | + expect(test_provider_with_insync).to receive(:insync?) |
175 | 179 | expect { custom_insync_property.insync?('foo') }.to raise_error(Puppet::DevError, %r{returned a String with a value of "true" instead of true/false}) |
176 | 180 | end |
177 | 181 | end |
178 | 182 |
|
179 | 183 | context 'when custom insync from the provider returns a symbol for the result' do |
180 | 184 | it 'raises an explanatory DevError' do |
181 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(:true) # rubocop:disable Lint/BooleanSymbol |
| 185 | + allow(test_provider_with_insync).to receive(:insync?).and_return(:true) # rubocop:disable Lint/BooleanSymbol |
| 186 | + expect(test_provider_with_insync).to receive(:insync?) |
182 | 187 | expect { custom_insync_property.insync?('foo') }.to raise_error(Puppet::DevError, %r{returned a Symbol with a value of :true instead of true/false}) |
183 | 188 | end |
184 | 189 | end |
185 | 190 |
|
186 | 191 | context 'when insync? returned an unexpected result class' do |
187 | 192 | it 'raises an explanatory DevError' do |
188 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(foo: 1) |
| 193 | + allow(test_provider_with_insync).to receive(:insync?).and_return(foo: 1) |
| 194 | + expect(test_provider_with_insync).to receive(:insync?) |
189 | 195 | expect { custom_insync_property.insync?('foo') }.to raise_error(Puppet::DevError, %r{returned a Hash with a value of \{:foo=>1\} instead of true/false}) |
190 | 196 | end |
191 | 197 | end |
|
208 | 214 |
|
209 | 215 | context 'when insync? returns nil for the result' do |
210 | 216 | it 'relies on Puppet::Property.change_to_s for change reporting' do |
211 | | - expect(test_provider_with_insync).to receive(:insync?).and_return([nil, 'custom change message']) |
| 217 | + allow(test_provider_with_insync).to receive(:insync?).and_return([nil, 'custom change message']) |
| 218 | + expect(test_provider_with_insync).to receive(:insync?) |
212 | 219 | expect(custom_insync_property.insync?('Foo')).to be(false) |
213 | 220 | expect(custom_insync_property.change_to_s('Foo', 'foo')).to match(/changed 'Foo' to 'foo'/) |
214 | 221 | end |
|
217 | 224 | context 'when insync? returns a change message' do |
218 | 225 | context 'when the message is empty' do |
219 | 226 | it 'relies on Puppet::Property.change_to_s for change reporting' do |
220 | | - expect(test_provider_with_insync).to receive(:insync?).and_return([false, '']) |
| 227 | + allow(test_provider_with_insync).to receive(:insync?).and_return([false, '']) |
| 228 | + expect(test_provider_with_insync).to receive(:insync?) |
221 | 229 | expect(custom_insync_property.insync?('Foo')).to be(false) |
222 | 230 | expect(custom_insync_property.change_to_s('Foo', 'foo')).to match(/changed 'Foo' to 'foo'/) |
223 | 231 | end |
224 | 232 | end |
225 | 233 |
|
226 | 234 | context 'when the result is nil' do |
227 | 235 | it 'relies on Puppet::Property.change_to_s for change reporting' do |
228 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(nil) |
| 236 | + allow(test_provider_with_insync).to receive(:insync?).and_return(nil) |
| 237 | + expect(test_provider_with_insync).to receive(:insync?) |
229 | 238 | expect(custom_insync_property.insync?('Foo')).to be(false) |
230 | 239 | expect(custom_insync_property.change_to_s('Foo', 'foo')).to match(/changed 'Foo' to 'foo'/) |
231 | 240 | end |
232 | 241 | end |
233 | 242 |
|
234 | 243 | context 'when the result is not nil and the message is not empty' do |
235 | 244 | it 'passes the message for change_to_s' do |
236 | | - expect(test_provider_with_insync).to receive(:insync?).and_return([false, 'custom change log']) |
| 245 | + allow(test_provider_with_insync).to receive(:insync?).and_return([false, 'custom change log']) |
| 246 | + expect(test_provider_with_insync).to receive(:insync?) |
237 | 247 | expect(custom_insync_property.insync?('Foo')).to be(false) |
238 | 248 | expect(custom_insync_property.change_to_s('Foo', 'foo')).to match(/custom change log/) |
239 | 249 | end |
|
251 | 261 | end |
252 | 262 |
|
253 | 263 | it 'passes the default message for change reporting if insync? did not return a string' do |
254 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(false) |
| 264 | + allow(test_provider_with_insync).to receive(:insync?).and_return(false) |
| 265 | + expect(test_provider_with_insync).to receive(:insync?) |
255 | 266 | custom_insync_property.insync?('Foo') |
256 | 267 | expect(custom_insync_property.change_to_s(false, true)).to match(/Custom insync logic determined that this resource is out of sync/) |
257 | 268 | end |
258 | 269 |
|
259 | 270 | it 'passes the string returned by insync? for change reporting' do |
260 | | - expect(test_provider_with_insync).to receive(:insync?).and_return(insync_result) |
| 271 | + allow(test_provider_with_insync).to receive(:insync?).and_return(insync_result) |
| 272 | + expect(test_provider_with_insync).to receive(:insync?) |
261 | 273 | custom_insync_property.insync?('Foo') |
262 | 274 | expect(custom_insync_property.change_to_s(false, true)).to be insync_result[1] |
263 | 275 | end |
|
0 commit comments