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

matcher for less-restrictive comparison #318

Merged
merged 8 commits into from Dec 11, 2015
Merged

Conversation

chris-rock
Copy link
Contributor

This matcher implements a less-restrictive comparison. Currently, it was not possible to write integer comparison (#308)

describe sshd_config do
  its('Port') { should eq '22' } # works
  its('Port') { should eq 22 } # does not work
end

As highlighted in #307 some resources have case-insensitive values, and I would like tests write

describe auditd_conf do
   its('log_format') { should eq 'raw' } # works
   its('log_format') { should eq 'RAW' } # does not work
end

This PR introduces a new comparison matcher cmp, that covers those cases:

describe sshd_config do
  its('Port') { should cmp '22' }
  its('Port') { should cmp 22 } # works with integer
  its('Port') { should cmp 22.0 } # also understand float
  its('Port') { should_not cmp 22.1 }

  # case-insensitive
  its('LogLevel') { should cmp 'INFO' } 
  its('LogLevel') { should cmp 'info' }
  its('LogLevel') { should cmp 'InfO' }
end

@chris-rock chris-rock added the Type: Enhancement Improves an existing feature label Dec 11, 2015
@chris-rock chris-rock self-assigned this Dec 11, 2015
@chris-rock chris-rock changed the title add new cmp matcher matcher for less-restrictive comparison Dec 11, 2015
@chris-rock
Copy link
Contributor Author

fixes #307
fixes #308


its('log_format') { should cmp 'raw' }
its('max_log_file') { should cmp 6 }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we establish cmp as the default matcher instead of eq for auditd_conf? Since the resource would be perfect for that! (i.e. just swap with eq + love the explanation!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great idea. I updated the docs.

@arlimus
Copy link
Contributor

arlimus commented Dec 11, 2015

Really great new functionality, love this from a user's standpoint! Great feature, thank you @chris-rock 🎅 👍

arlimus added a commit that referenced this pull request Dec 11, 2015
matcher for less-restrictive comparison
@arlimus arlimus merged commit 494ed70 into master Dec 11, 2015
@arlimus arlimus deleted the chris-rock/cmp-matcher branch December 11, 2015 16:58
@arlimus arlimus mentioned this pull request Feb 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants