-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defined types facts as default parameter not working #13
Comments
@b4ldr taking a look through, it seems like the issue might be with the facts caching in https://github.com/voxpupuli/rspec-puppet-facts/blob/master/lib/rspec-puppet-facts.rb#L31-L50 I suspect this issue should be moved to that repository where the maintainers will have better context and availability to solve the problem at the right level. |
@b4ldr I would recommend to use different names so you don't shadow, but that's not the real issue. You don't scope the facts properly. What you must do is to call describe 'example::rspec_define' do
on_supported_os(test_on).each do |os, os_facts|
context os do
let(:facts) { os_facts }
let(:title) { "test-#{os}" }
context 'test' do
it { is_expected.to compile }
it { is_expected.to contain_file('/tmp/T291374').with_content(/#{facts[:os]['distro']['codename']}/) }
end
end
end
end This has to do with rspec itself where it first generates classes but it keeps a reference to the You can see this as well with this test: require 'voxpupuli/test/spec_helper'
test_on = { supported_os: [ 'operatingsystem' => 'Debian', 'operatingsystemrelease' => ['9','10']]}
describe 'example::rspec_define' do
on_supported_os(test_on).each do |os, os_facts|
let(:facts) { os_facts }
let(:title) { "test-#{os}" }
context os do
it { is_expected.to compile }
it { is_expected.to contain_file('/tmp/T291374').with_content(/#{facts[:os]['distro']['codename']}/) }
end
end
end This results in:
Note how the context is printed correctly but then the facts have an old value. Edit: I just realized that with voxpupuli/rspec-puppet-facts#132 this wouldn't be a problem: all this complex boiler plate is hidden. |
@ekohl thanks for the fix and explanation closing as #invalid |
update spec test to test multiple distros: puppetlabs/rspec-puppet#13 Change-Id: I0fd23fdc44b57cb23d56233fb08c24a406aa4af6
Describe the Bug
With a defined that has a default parameter which uses a fact for the default value e.g.
Testing using rspec-puppet-tests has no affect on the default value. It appears that all tests use the last value in the on_supported_os iterator.
The test i used is:
Expected Behaviour
All test should pass
Actual Behaviour
The file content test above fails when testing
debian-10-x86_64
with the following errorSteps to Reproduce
I have created a specific repo to demonstrate this issue
Steps to reproduce the behavior:
git clone https://github.com/b4ldr/T291374/
cd T291374
bundle install
bundle exec rake spec
The text was updated successfully, but these errors were encountered: