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

rspec-its breaking InSpec #44

Open
walterdolce opened this issue May 23, 2017 · 4 comments · May be fixed by #68
Open

rspec-its breaking InSpec #44

walterdolce opened this issue May 23, 2017 · 4 comments · May be fixed by #68

Comments

@walterdolce
Copy link

Hi,

When I use InSpec's parse_config_file resource to verify the content of an ini-like config file structured like so:

[beaver]
foo: baz

[/var/log/apache2/access.log]
bar: baz

And I have the following spec:

    describe parse_config_file('/etc/beaver/beaver.conf', {
        assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
        comment_character: '#'
    }) do
        its('beaver') {
            should include('foo' => 'baz')
        }

        its('/var/log/apache2/access.log') {
            should include('bar' => 'baz')
        }
    end

The following error occurs:

∅  undefined method `log' for nil:NilClass

I believe this is being caused by this line of code which is splitting the value by dot (.):
https://github.com/rspec/rspec-its/blob/master/lib/rspec/its.rb#L113

This is effectively causing InSpec (and any other rspec "wrapper" feeding that code path something which includes a dot) to break. Not being a core rspec developer I'm not sure how I could contribute to solving this problem via Pull Requests etc.

Any advice would be much appreciated.

Thank you.

@walterdolce walterdolce changed the title rspec-its beaking InSpec rspec-its breaking InSpec May 23, 2017
walterdolce added a commit to walterdolce/rspec-its that referenced this issue May 23, 2017
@JonRowe
Copy link
Member

JonRowe commented Jan 10, 2019

Apologies for the long time taken to come back to you on this, to fix this you'd have to add a way to escape the dot for people using long string keys like this.

@lavahot
Copy link

lavahot commented Mar 19, 2019

This is actually a breaking bug for some of my tests. Any chance you can submit a pull request, @walterdolce ?

@walterdolce walterdolce linked a pull request Mar 19, 2019 that will close this issue
@walterdolce
Copy link
Author

@lavahot done :)

@walterdolce
Copy link
Author

It's not really a fix. It's actually a new "feature" as my PR above adds the ability to define a split_attribute_by option to define how to split attribute names.

Then, within InSpec I do something like this:

describe parse_config_file('/etc/beaver/beaver.conf', {
        assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
        comment_character: '#',
        split_attribute_by: '#' // skips splitting by dot
    }) do
        its('beaver') {
            should include('foo' => 'baz')
        }

        its('/var/log/apache2/access.log') {
            should include('bar' => 'baz')
        }
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants