Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspec json resource . example not working #631

Closed
alexpop opened this issue Apr 11, 2016 · 1 comment · Fixed by #647
Closed

Inspec json resource . example not working #631

alexpop opened this issue Apr 11, 2016 · 1 comment · Fixed by #647
Labels
Type: Bug Feature not working as expected

Comments

@alexpop
Copy link
Contributor

alexpop commented Apr 11, 2016

Description

The json inspec resource not working with '.' as separators.

InSpec and Platform Version

$ bin/inspec version
0.18.0

OS X 10.11.3

Replication Case

With the following json file:

{
  "cookbook_locks": {
    "omnibus": {
      "version": "2.2.0",
      "identifier": "22b35f3f9273cb8d8b6ac3684cb92f960597ff2f"
    }
  }
}

The json inspec resource documentation and example show this:

describe json('policyfile.lock.json') do
  its('cookbook_locks.omnibus.version') { should eq('2.2.0') }
end

On execution, it gives this error message:

$ bin/inspec exec /tmp/json_test.rb
F
Failures:
  1) Json /tmp/Policyfile.lock.json cookbook_locks.omnibus.version
     Failure/Error: with.run_specs(tests)

     NoMethodError:
       undefined method `omnibus' for #<Hash:0x007f8a62c817b8>
     # /tmp/json_test.rb:2:in `block (2 levels) in load'
     # ./lib/inspec/runner_rspec.rb:67:in `run'
     # ./lib/utils/base_cli.rb:70:in `run_tests'
     # ./lib/inspec/cli.rb:113:in `exec'

Finished in 0.00093 seconds (files took 1.06 seconds to load)
1 example, 1 failure

Failed examples:
rspec  # Json /tmp/Policyfile.lock.json cookbook_locks.omnibus.version

The workaround I found was to run it like this:

describe json('/tmp/Policyfile.lock.json') do
  its(['cookbook_locks','omnibus','version']) { should eq('2.2.0') }
end

producing the correct output:

$ bin/inspec exec /tmp/json_test.rb
.
Finished in 0.00086 seconds (files took 1.01 seconds to load)
1 example, 0 failures
@chris-rock chris-rock added the Type: Bug Feature not working as expected label Apr 11, 2016
@chris-rock
Copy link
Contributor

Unfortunately, this is an issue with its. We need to update the documentation for the resource to use:

describe json('/tmp/Policyfile.lock.json') do
  its(['cookbook_locks','omnibus','version']) { should eq('2.2.0') }
end

for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants