2016-09-22 14:43:57 +02:00
|
|
|
---
|
|
|
|
title: About the gem Resource
|
|
|
|
---
|
|
|
|
|
|
|
|
# gem
|
|
|
|
|
|
|
|
Use the `gem` InSpec audit resource to test if a global Gem package is installed.
|
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 12:03:23 -07:00
|
|
|
## Syntax
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
A `gem` resource block declares a package and (optionally) a package version:
|
|
|
|
|
2017-03-24 22:28:42 -07:00
|
|
|
describe gem('gem_package_name', 'gem_binary') do
|
2016-09-22 14:43:57 +02:00
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `('gem_package_name')` must specify a Gem package, such as `'rubocop'`
|
2017-03-24 22:28:42 -07:00
|
|
|
* `('gem_binary')` can specify the path to a non-default gem binary, defaults to `'gem'`
|
2016-09-22 14:43:57 +02:00
|
|
|
* `be_installed` is a valid matcher for this resource
|
|
|
|
|
2017-10-03 14:35:10 -07:00
|
|
|
<br>
|
2016-09-22 14:43:57 +02:00
|
|
|
|
2018-02-06 03:31:11 -08:00
|
|
|
## Resource Property Examples
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
The following examples show how to use this InSpec audit resource.
|
|
|
|
|
2016-09-27 12:03:23 -07:00
|
|
|
### Verify that a gem package is installed, with a specific version
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
describe gem('rubocop') do
|
|
|
|
it { should be_installed }
|
|
|
|
its('version') { should eq '0.33.0' }
|
|
|
|
end
|
|
|
|
|
2016-09-27 12:03:23 -07:00
|
|
|
### Verify that a gem package is not installed
|
2016-09-22 14:43:57 +02:00
|
|
|
|
|
|
|
describe gem('rubocop') do
|
|
|
|
it { should_not be_installed }
|
|
|
|
end
|
2017-03-24 22:28:42 -07:00
|
|
|
|
|
|
|
### Verify that a gem package is installed in an omnibus environment
|
|
|
|
|
|
|
|
describe gem('pry', '/opt/ruby-2.3.1/embedded/bin/gem') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
### Verify that a gem package is installed in a chef omnibus environment
|
|
|
|
|
|
|
|
describe gem('chef-sugar', :chef) do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
### Verify that a gem package is installed in a chef-server omnibus environment
|
|
|
|
|
|
|
|
describe gem('knife-backup', :chef_server) do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
2017-10-03 14:35:10 -07:00
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
## Matchers
|
|
|
|
|
2018-01-31 04:24:16 -08:00
|
|
|
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
2017-10-03 14:35:10 -07:00
|
|
|
|
|
|
|
### be_installed
|
|
|
|
|
|
|
|
The `be_installed` matcher tests if the named Gem package is installed:
|
|
|
|
|
|
|
|
it { should be_installed }
|
|
|
|
|
|
|
|
### version
|
|
|
|
|
|
|
|
The `version` matcher tests if the named package version is on the system:
|
|
|
|
|
|
|
|
its('version') { should eq '0.33.0' }
|