Hi,
we use a custom function (extlib::read_url) which we want to stub for every profile and role class unit test.
We tried using before within Spec.configure:
RSpec.configure do |c|
c.before :each do
Puppet::Functions.create_function(:'profile::read_url') do
dispatch :read_url do
param 'Stdlib::HTTPUrl', :url
return_type 'String'
end
def read_url(url)
'ssh-rsa AAAAAAAAAzuozgouzvouzvf== us...@domain.tld'
end
end
end
end
When stubbing the function in spec_helper_local.rb file, we must add the dispatch and the def.
But the test still use the original function.
I also tried “overloading” the function in a spec/fixtures/override_modules directory.
Unit tests still take the original function.
Even adding shared_context is not working.
Has anyone an idea, on how to solve this.
I don’t want to add the function stub (which works flawlessly) into every class unit test.
This is a working example where we stub inside the class unit test:
require 'spec_helper'
describe 'profile::base::user_accounts' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
Puppet::Functions.create_function(:'profile::read_url') do
return 'ssh-rsa AAAAAAAAAzuozgouzvouzvf== us...@domain.tld'
end
it {
is_expected.to compile }
end
end
end
Best,
Martin