Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/loadjson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Puppet::Parser::Functions
url = args[0]
end
begin
contents = OpenURI.open_uri(url, http_options)
contents = OpenURI.open_uri(url, http_options).read
rescue OpenURI::HTTPError => e
res = e.io
warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'")
Expand Down
9 changes: 4 additions & 5 deletions spec/functions/loadjson_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with(filename).and_return(true).once
allow(File).to receive(:read).with(filename).and_return(json).once
allow(File).to receive(:read).with(filename).and_return(json).once
if Puppet::PUPPETVERSION[0].to_i < 8
allow(PSON).to receive(:load).with(json).and_return(data).once
else
Expand Down Expand Up @@ -98,7 +97,7 @@
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }

it {
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json)
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(StringIO.new(json))
if Puppet::PUPPETVERSION[0].to_i < 8
expect(PSON).to receive(:load).with(json).and_return(data).once
else
Expand All @@ -118,7 +117,7 @@
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }

it {
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json)
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(StringIO.new(json))
if Puppet::PUPPETVERSION[0].to_i < 8
expect(PSON).to receive(:load).with(json).and_return(data).once
else
Expand All @@ -138,7 +137,7 @@
let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }

it {
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(json)
expect(OpenURI).to receive(:open_uri).with(url_no_auth, basic_auth).and_return(StringIO.new(json))
if Puppet::PUPPETVERSION[0].to_i < 8
expect(PSON).to receive(:load).with(json).and_return(data).once
else
Expand All @@ -155,7 +154,7 @@
let(:json) { ',;{"key":"value"}' }

it {
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(json)
expect(OpenURI).to receive(:open_uri).with(filename, {}).and_return(StringIO.new(json))
if Puppet::PUPPETVERSION[0].to_i < 8
expect(PSON).to receive(:load).with(json).once.and_raise StandardError, 'Something terrible have happened!'
else
Expand Down