Yes, you can use ruby code in controls and custom resources, but remember of the agentless nature of InSpec. Gems that require execution on the target node will not work. I’ve updated gordon_config.rb with a few lines of ruby and comments.
You can’t use Chef DSL, but you can use InSpec resource DSL. More details under docs/dsl_inspec.rst
Yes you can
Can you please describe the use-case here? You can get detailed test output using --format. For instance:
$ bin/inspec exec examples/profile --controls gordon-1.0 --format fulljson | jq
{
"version": "3.4.4",
"examples": [
{
"id": "gordon-1.0",
"title": "Verify the version number of Gordon",
"desc": "An optional description...",
"code": "control 'gordon-1.0' do\n impact 0.7\n title 'Verify the version number of Gordon'\n desc 'An optional description...'\n describe gordon_config do\n its('version') { should eq('1.0') }\n its('size') { should <= 20 }\n end\nend\n",
"impact": 0.7,
"status": "pending",
"code_desc": "gordon_config Can't find file \"/tmp/gordon/config.yaml\"",
"ref": "examples/profile/controls/gordon.rb",
"ref_line": 18,
"run_time": 3.1e-05,
"start_time": "2016-03-24 20:21:24 +0000",
"pending": "Can't find file \"/tmp/gordon/config.yaml\""
}
],
"summary": {
"duration": 0.000576,
"example_count": 1,
"failure_count": 0,
"pending_count": 1
},
"summary_line": "1 example, 0 failures, 1 pending",
"profiles": [
{
"name": "profile",
"title": "InSpec Example Profile",
"maintainer": "Chef Software, Inc.",
"copyright": "Chef Software, Inc.",
"copyright_email": "support@chef.io",
"license": "Apache 2 license",
"summary": "Demonstrates the use of InSpec Compliance Profile",
"version": "1.0.0",
"supports": [
{
"os-family": "unix"
}
]
}
]
}
you asked for a use case with regard to “How do I return data to the test case say for example a simple string.”
lets user take a simple case. the linux (rhel) command: getenforce. It returns a simple string of the current selinux setting. I’d like to write a custom resource that return the string generated by the command. I was using this as a simple test so I could understand how custom resources worked.
I got the class to work but still don’t understand how to get the data from the the custom class to the test case thats calling it from the controls directory.
thanks for the help and the comments to the stuff in github.