Skip to content

Commit d466e7f

Browse files
author
Ciaran McCrisken
committed
(IAC-1228) Allow File.read to passthrough for JSON spec tests
In the context of Puppet 7 there are two subsequent calls to File.read from the catalog generated from the tests of `loadjson_spec.rb` and `load_module_metadata_spec.rb` Prior to this commit, these calls were causing exceptions from RSpec as the mock expectations for File.read were being thrown off. This did not manifest on Puppet 5 or 6. After this commit, any calls to File.read that do not conform to the expected arguments we want to mock a response for, are passed through to File.read.
1 parent b4605c2 commit d466e7f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

spec/functions/load_module_metadata_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
describe 'when calling with valid arguments' do
99
before :each do
10+
# In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock
11+
allow(File).to receive(:read).with(anything, anything).and_call_original
1012
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
1113
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1214
# Additional modules used by litmus which are identified while running these dues to being in fixtures

spec/functions/loadjson_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
describe 'when calling with valid arguments' do
88
before :each do
9+
# In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock
10+
allow(File).to receive(:read).with(anything, anything).and_call_original
911
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}')
1012
allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}')
1113
# Additional modules used by litmus which are identified while running these dues to being in fixtures

0 commit comments

Comments
 (0)