Hi - I was looking at the docs around the use of only_if in https://www.inspec.io/docs/reference/dsl_inspec/ and see that we can skip controls based on a condition. There was mention of the skip message (which always seem to default to "Skipped control due to only_if condition") but I don't see where that should be set. Also, the code snippet in the docs for only_if is not working for me but if I make it like so it works:
only_if do
command('redis-cli').exist?
end
or
only_if{command('redis-cli').exist?}
Any help to make the skip message more meaningful is appreciated. TIA!
Hello! only_if takes an optional String message parameter and a required block that should evaluate to a Boolean; if the block is false, the control will skip, with the message "Skipped due to YOURMESSAGE". It's mentioned on the InSpec DSL page you linked to (perhaps not prominently):
only_if('redis is not installed.') do
command('redis-cli').exist?
end
That's how it's supposed to work
You said it's "not working for you" - could you give more detail? Ruby syntax around block calls with a parameter can be sensitive to spaces....
# This is OK
only_if("it is Friday") { false }
# This will probably be a syntax error - note the space after "if"
only_if ("it is Friday") { false }