Skip to content
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

Refactor unit test #80

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

Valantin
Copy link
Contributor

Pull Request (PR) description

Refactoring the unit test to iterate on the supported os

This Pull Request (PR) fixes the following issues

Fixes #79

@Valantin Valantin force-pushed the add-rspec-puppet-facts branch from a6e3f03 to 498a143 Compare March 11, 2024 15:49
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You usually end up with code like:

describe 'openvmtools' do
  on_supported_os.each do |os, os_facts|
    context "os #{os}" do
      let(:facts) { os_facts.merge(virtual: 'vmware') }
      let(:package_name) do
        case facts[:os]['family']
        when 'RedHat'
          'open-vm-tools'
        else
          'whatever'
        end

        it { is_expected.to contain_package(package_name) }
      end
    end
  end
end

Note the difference between os_facts and facts is that the latter one is the fully merge one where os_facts is provided by the top layer. You can only use it within it blocks.

@Valantin Valantin force-pushed the add-rspec-puppet-facts branch from 498a143 to 5c6ee95 Compare March 11, 2024 16:30
@Valantin Valantin requested a review from ekohl March 11, 2024 16:34
spec/classes/openvmtools_init_spec.rb Outdated Show resolved Hide resolved
spec/classes/openvmtools_init_spec.rb Outdated Show resolved Hide resolved
'vmware_guestd'
else
'vmtoolsd'
end
Copy link
Member

@jay7x jay7x Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see missing a end here.. but maybe my builtin ruby interpreter misinterprets something in the end of the day 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end is after the last it {} statement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jay7x is correct that the let block needs to be closed

spec/classes/openvmtools_init_spec.rb Outdated Show resolved Hide resolved
@Valantin Valantin force-pushed the add-rspec-puppet-facts branch from d063576 to 96449dc Compare March 12, 2024 14:25
@Valantin Valantin force-pushed the add-rspec-puppet-facts branch from 96449dc to 699a160 Compare March 12, 2024 14:27
@ekohl
Copy link
Member

ekohl commented Mar 12, 2024

Is it still WIP (as the title says) or ready to be merged?

@Valantin Valantin changed the title WIP: Refactoring unit test Refactoring unit test Mar 12, 2024
@Valantin
Copy link
Contributor Author

For now I think is ok

@bastelfreak bastelfreak changed the title Refactoring unit test Refactor unit test Mar 12, 2024
@bastelfreak bastelfreak merged commit 9459159 into voxpupuli:master Mar 12, 2024
22 checks passed
@Valantin Valantin deleted the add-rspec-puppet-facts branch March 29, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit test refactoring
4 participants