Hi Nick, This is working as expected. Many thanks for the fix.
Martin > On 8. Mar 2021, at 19:25, Nick Bertrand <[email protected]> wrote: > > Hi Martin, > > Using rspec-puppet's pre_condition seems to work for me: > > RSpec.shared_context "read_url stub" do > let (:pre_condition) do > ' > function profile::read_url(String $arg) >> String { > return "ssh-rsa AAAAAAAAAzuozgouzvouzvf== [email protected]" > } > ' > end > end > > RSpec.configure do |c| > c.include_context "read_url stub" > end > > HTH, > > Nick > > On Fri, Mar 5, 2021 at 7:04 AM Martin Alfke <[email protected] > <mailto:[email protected]>> wrote: > 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== [email protected]' > 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== [email protected]' > end > > it { is_expected.to <http://is_expected.to/> compile } > end > end > end > > Best, > Martin > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:puppet-users%[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/422A162D-B1C9-48B1-902C-8E70F1D945A5%40gmail.com > > <https://groups.google.com/d/msgid/puppet-users/422A162D-B1C9-48B1-902C-8E70F1D945A5%40gmail.com>. > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/CAP15v%2B9WC3ugudPH5mLitVygvdgpj9Zjm_ppJZnPfKTA_uKJBg%40mail.gmail.com > > <https://groups.google.com/d/msgid/puppet-users/CAP15v%2B9WC3ugudPH5mLitVygvdgpj9Zjm_ppJZnPfKTA_uKJBg%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/9801F03D-A0D9-45B2-AD13-343CA7CA51DD%40gmail.com.
