Sha256: 86ae425a4f4c9c8d25c6b0c5056bb5aefe229fee80192e13db648b56b8d47bdb

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

---
title: About the gem Resource
platform: os
---

# gem

Use the `gem` InSpec audit resource to test if a global Gem package is installed.

<br>

## Syntax

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 resource

<br>

## Resource Property Examples

The following examples show how to use this InSpec audit resource.

### Verify that a gem package is installed, with a specific version

    describe gem('rubocop') do
      it { should be_installed }
      its('version') { should eq '0.33.0' }
    end

### Verify that a gem package is not installed

    describe gem('rubocop') do
      it { should_not be_installed }
    end

### 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

<br>

## Matchers

For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).

### 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' }

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
inspec-2.1.81 docs/resources/gem.md.erb
inspec-2.1.21 docs/resources/gem.md.erb
inspec-2.1.10 docs/resources/gem.md.erb
inspec-2.0.32 docs/resources/gem.md.erb
inspec-2.0.17 docs/resources/gem.md.erb