InSpec Glossary

Basic Syntax

describe foo('/path/to/foo.txt') do
    its('blah') { should cmp '123' }
    it { should exist }
    it { should be_reasonable }
    it { should_not be_ridiculous }
end

Basic Elements:

describe foo, where

  • foo is the resource

describe foo (‘/path/to/foo.txt’), where

  • '/path/to/foo.txt' is the resource parameter

Tests:

its(‘blah’) { should cmp ‘123’ } is an individual test, where

  • blah is a property
  • { should cmp ‘123’ } is a condition statement
  • should is the condition
  • cmp is the matcher
  • '123' is the expected result

{ should exist } is a condition statement, where

  • should is the condition
  • exist is the matcher

{ should be_reasonable } is a condition statement, where

  • should is the condition
  • be_reasonable is the matcher

{ should_not be_ridiculous } is a negative condition statement, where

  • should_not is the negative condition
  • be_ridiculous is the matcher

Advanced Syntax

describe foos('/path/to/foo.txt', ssl_verify: true).where { names == 'blah' } do
    its('jared') { should cmp >= 123 }
    its('jared.sort.first.monkey') { should be `loud` }
    its(['jared', 'monkey.with.dots']) { should be `loud` }
end

Advanced Elements:

describe foos, where

  • foos is a plural resource

describe foos (‘/path/to/foo.txt’, ssl_verify: true), where

  • '/path/to/foo.txt' and ssl_verify: true are the resource parameters. Resources take one or more parameters.

Filters:

describe foos (‘/path/to/foo.txt’, ssl_verify: true).where { names == ‘blah’ }

  • .where { names == 'blah' } is an example of a filter.
  • { names == 'blah' } is an example of a filter clause
  • Some resources support one or more filters.
  • Filters are used on plural resources.
  • Some resources, such as etc_hosts are explicitly plural, while others, such as passwd are implicitly plural.

{ names == ‘my-name’ && spots == true } are filter criteria

  • names compares output to blah
  • has spots evaluates to true or false

Properties:

its(‘jared’) { should cmp >= 123 }

  • jared is the property

{ should cmp >= 123 } is a conditional statement that uses a matcher with an operator and expected value.

  • cmp is the matcher
  • >= is the operator (some matchers accept operators)
  • 123 is the expected value

Properties with advanced usage:

Some properties may have advanced usage:

its ('jared.sort.first.monkey') { should beloud}

  • jared.sort.first.monkey is an example of the jared property with an advanced usage