Skip to content

Commit

Permalink
Add additional example for matching crontab commands
Browse files Browse the repository at this point in the history
As raised in #1526, adding an additional example showing how
a user can use the `where` accessor to find commands matching
a pattern and write a test using the results.

Signed-off-by: Adam Leff <adam@leff.co>
  • Loading branch information
adamleff committed Mar 14, 2017
1 parent 546486f commit feef6ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/resources/crontab.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ The following examples show how to use this InSpec audit resource.
describe crontab.where({'hour' => '*', 'minute' => '*'}) do
its('entries.length') { should cmp '0' }
end

### Test that the logged-in user's crontab contains a single command that matches a mattern

describe crontab.where { command =~ /a partial command string/ } do
its('entries.length') { should cmp 1 }
end
4 changes: 4 additions & 0 deletions lib/resources/crontab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class Crontab < Inspec.resource(1)
describe crontab.where({'hour' => '*', 'minute' => '*'}) do
its('entries.length') { should cmp '0' }
end
describe crontab.where { command =~ /a partial command string/ } do
its('entries.length') { should cmp 1 }
end
"

attr_reader :params
Expand Down

0 comments on commit feef6ac

Please sign in to comment.