4 it { is_expected.not_to eq(nil) }
5 it { is_expected.to run.with_params().and_raise_error(ArgumentError, /wrong number of arguments/i) }
7 describe "when calling with valid arguments" do
9 allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
10 allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
13 context 'when a non-existing file is specified' do
15 if Puppet::Util::Platform.windows?
22 allow(File).to receive(:exists?).with(filename).and_return(false).once
23 allow(PSON).to receive(:load).never
25 it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
26 it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) }
27 it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) }
30 context 'when an existing file is specified' do
32 if Puppet::Util::Platform.windows?
38 let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} }
39 let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
41 allow(File).to receive(:exists?).with(filename).and_return(true).once
42 allow(File).to receive(:read).with(filename).and_return(json).once
43 allow(File).to receive(:read).with(filename).and_return(json).once
44 allow(PSON).to receive(:load).with(json).and_return(data).once
46 it { is_expected.to run.with_params(filename).and_return(data) }
49 context 'when the file could not be parsed' do
51 if Puppet::Util::Platform.windows?
57 let(:json) { '{"key":"value"}' }
59 allow(File).to receive(:exists?).with(filename).and_return(true).once
60 allow(File).to receive(:read).with(filename).and_return(json).once
61 allow(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
63 it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }