Use the gem Chef InSpec audit resource to test if a global Gem package is installed.
This resource is distributed along with Chef InSpec itself. You can use it automatically.
This resource first became available in v1.0.0 of InSpec.
A gem resource block declares a package and (optionally) a package version:
describe gem('gem_package_name', 'gem_binary') do
it { should be_installed }
end
where
('gem_package_name') must specify a Gem package, such as 'rubocop'
('gem_binary') can specify the path to a non-default gem binary, defaults to 'gem'
be_installed is a valid matcher for this resourceversion (String)The version property returns a string of the default version on the system:
its('version') { should eq '0.33.0' }
versionsThe versions property returns an array of strings of all the versions of the gem installed on the system:
its('versions') { should include /0.33/ }
The following examples show how to use this Chef InSpec audit resource.
describe gem('rubocop') do
it { should be_installed }
its('version') { should eq '1.22.0' }
end
describe gem('rubocop') do
it { should be_installed }
its('versions') { should include /1.21.0/ }
its('versions.count') { should_not be > 3 }
end
describe gem('rubocop') do
it { should_not be_installed }
end
describe gem('pry', '/opt/ruby-3.0.2/embedded/bin/gem') do
it { should be_installed }
end
describe gem('chef-sugar', :chef) do
it { should be_installed }
end
describe gem('knife-backup', :chef_server) do
it { should be_installed }
end
The version property returns a string of the default version on the system:
its('version') { should eq '1.22.0' }
The versions property returns an array of strings of all the versions of the gem installed on the system:
its('versions') { should include /1.22/ }
For a full list of available matchers, please visit our matchers page.
The be_installed matcher tests if the named Gem package is installed:
it { should be_installed }
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/gem/