2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
title: About the gem Resource
|
|
|
|
---
|
|
|
|
|
|
|
|
# gem
|
|
|
|
|
|
|
|
Use the `gem` InSpec audit resource to test if a global Gem package is installed.
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Syntax
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
A `gem` resource block declares a package and (optionally) a package version:
|
|
|
|
|
|
|
|
describe gem('gem_package_name') do
|
|
|
|
it { should be_installed }
|
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `('gem_package_name')` must specify a Gem package, such as `'rubocop'`
|
|
|
|
* `be_installed` is a valid matcher for this resource
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Matchers
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
This InSpec audit resource has the following matchers:
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### be
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
<%= partial "/shared/matcher_be" %>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### be_installed
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `be_installed` matcher tests if the named Gem package is installed:
|
|
|
|
|
|
|
|
it { should be_installed }
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### cmp
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
<%= partial "/shared/matcher_cmp" %>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### eq
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
<%= partial "/shared/matcher_eq" %>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### include
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
<%= partial "/shared/matcher_include" %>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### match
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
<%= partial "/shared/matcher_match" %>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### version
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `version` matcher tests if the named package version is on the system:
|
|
|
|
|
|
|
|
its('version') { should eq '0.33.0' }
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Examples
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The following examples show how to use this InSpec audit resource.
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### Verify that a gem package is installed, with a specific version
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
describe gem('rubocop') do
|
|
|
|
it { should be_installed }
|
|
|
|
its('version') { should eq '0.33.0' }
|
|
|
|
end
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### Verify that a gem package is not installed
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
describe gem('rubocop') do
|
|
|
|
it { should_not be_installed }
|
|
|
|
end
|