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== u...@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== u...@domain.tld'
      end

      it { 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/422A162D-B1C9-48B1-902C-8E70F1D945A5%40gmail.com.

Reply via email to