|
4 | 4 | it { is_expected.not_to eq(nil) }
|
5 | 5 | it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) }
|
6 | 6 |
|
7 |
| - context 'when a non-existing file is specified' do |
8 |
| - let(:filename) { '/tmp/doesnotexist' } |
9 |
| - before { |
10 |
| - File.expects(:exists?).with(filename).returns(false).once |
11 |
| - PSON.expects(:load).never |
12 |
| - } |
13 |
| - it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } |
14 |
| - end |
| 7 | + describe "when calling with valid arguments" do |
| 8 | + before :each do |
| 9 | + if RSpec.configuration.puppet_future |
| 10 | + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}') |
| 11 | + else |
| 12 | + allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}') |
| 13 | + end |
| 14 | + end |
15 | 15 |
|
16 |
| - context 'when an existing file is specified' do |
17 |
| - let(:filename) { '/tmp/doesexist' } |
18 |
| - let(:data) { { 'key' => 'value' } } |
19 |
| - let(:json) { '{"key":"value"}' } |
20 |
| - before { |
21 |
| - File.expects(:exists?).with(filename).returns(true).once |
22 |
| - File.expects(:read).with(filename).returns(json).once |
23 |
| - PSON.expects(:load).with(json).returns(data).once |
24 |
| - } |
25 |
| - it { is_expected.to run.with_params(filename).and_return(data) } |
26 |
| - end |
| 16 | + context 'when a non-existing file is specified' do |
| 17 | + let(:filename) { '/tmp/doesnotexist' } |
| 18 | + before { |
| 19 | + allow(File).to receive(:exists?).with(filename).and_return(false).once |
| 20 | + allow(PSON).to receive(:load).never |
| 21 | + } |
| 22 | + it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } |
| 23 | + end |
| 24 | + |
| 25 | + context 'when an existing file is specified' do |
| 26 | + let(:filename) { '/tmp/doesexist' } |
| 27 | + let(:data) { { 'key' => 'value' } } |
| 28 | + let(:json) { '{"key":"value"}' } |
| 29 | + before { |
| 30 | + allow(File).to receive(:exists?).with(filename).and_return(true).once |
| 31 | + allow(File).to receive(:read).with(filename).and_return(json).once |
| 32 | + allow(File).to receive(:read).with(filename).and_return(json).once |
| 33 | + allow(PSON).to receive(:load).with(json).and_return(data).once |
| 34 | + } |
| 35 | + it { is_expected.to run.with_params(filename).and_return(data) } |
| 36 | + end |
27 | 37 |
|
28 |
| - context 'when the file could not be parsed' do |
29 |
| - let(:filename) { '/tmp/doesexist' } |
30 |
| - let(:json) { '{"key":"value"}' } |
31 |
| - before { |
32 |
| - File.expects(:exists?).with(filename).returns(true).once |
33 |
| - File.expects(:read).with(filename).returns(json).once |
34 |
| - PSON.stubs(:load).with(json).once.raises StandardError, 'Something terrible have happened!' |
35 |
| - } |
36 |
| - it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } |
| 38 | + context 'when the file could not be parsed' do |
| 39 | + let(:filename) { '/tmp/doesexist' } |
| 40 | + let(:json) { '{"key":"value"}' } |
| 41 | + before { |
| 42 | + allow(File).to receive(:exists?).with(filename).and_return(true).once |
| 43 | + allow(File).to receive(:read).with(filename).and_return(json).once |
| 44 | + allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!' |
| 45 | + } |
| 46 | + it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) } |
| 47 | + end |
37 | 48 | end
|
38 | 49 | end
|
0 commit comments