mirror of
https://github.com/inspec/inspec
synced 2024-11-30 08:30:39 +00:00
f32bcdb74d
* Adds glossary.md file Signed-off-by: kgarmoe <kgarmoe@chef.io> * Adds glossary to sidebar and updates page formatting Signed-off-by: kagarmoe <kgarmoe@chef.io> * Changes glossary layout Signed-off-by: kagarmoe <kgarmoe@chef.io> * Replaces errant tic Signed-off-by: kagarmoe <kgarmoe@chef.io> * Requested changes Signed-off-by: kagarmoe <kgarmoe@chef.io> * Clarifies filter clause Signed-off-by: kagarmoe <kgarmoe@chef.io>
2.7 KiB
2.7 KiB
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 conditioncmp
is the matcher'123'
is the expected result
{ should exist } is a condition statement, where
should
is the conditionexist
is the matcher
{ should be_reasonable } is a condition statement, where
should
is the conditionbe_reasonable
is the matcher
{ should_not be_ridiculous } is a negative condition statement, where
should_not
is the negative conditionbe_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'
andssl_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 aspasswd
are implicitly plural.
{ names == 'my-name' && spots == true } are filter criteria
names
compares output toblah
has spots
evaluates totrue
orfalse
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 be
loud }
jared.sort.first.monkey
is an example of thejared
property with an advanced usage