|
11 | 11 | allow(provider).to receive(:file_path).and_return('/tmp/foo')
|
12 | 12 | allow(provider).to receive(:read_file).and_return('foo = bar')
|
13 | 13 | allow(provider).to receive(:write_file).and_return(true)
|
| 14 | + allow(provider).to receive(:resource).and_return(key: 'your_key', line_number: 1, value: 'foo') |
14 | 15 | end
|
15 | 16 | # rubocop:enable RSpec/ReceiveMessages
|
16 | 17 |
|
|
29 | 30 | it 'has a method exists?' do
|
30 | 31 | expect(provider).to respond_to(:exists?)
|
31 | 32 | end
|
| 33 | + context '#exists?' do |
| 34 | + it 'returns true when a matching config item is found' do |
| 35 | + config_data = [{ key: 'your_key', value: 'your_value' }] |
| 36 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 37 | + |
| 38 | + expect(provider.exists?).to be true |
| 39 | + end |
| 40 | + |
| 41 | + it 'returns false when no matching config item is found' do |
| 42 | + config_data = [{ key: 'other_key', value: 'other_value' }] |
| 43 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 44 | + |
| 45 | + expect(provider.exists?).to be false |
| 46 | + end |
| 47 | + |
| 48 | + it 'raises an error when multiple matching config items are found' do |
| 49 | + config_data = [{ key: 'your_key', value: 'value1' }, { key: 'your_key', value: 'value2' }] |
| 50 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 51 | + |
| 52 | + expect { provider.exists? }.to raise_error(Puppet::Error, 'found multiple config items of your_key found, please fix this') |
| 53 | + end |
| 54 | + end |
32 | 55 |
|
33 | 56 | it 'has a method create' do
|
34 | 57 | expect(provider).to respond_to(:create)
|
|
0 commit comments