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

teach cmp matcher octal tricks #324

Merged
merged 1 commit into from
Dec 17, 2015
Merged

Conversation

srenatus
Copy link
Contributor

This addresses #230. The underlying problem is that as far as I can tell no way to figure out if an Integer argument to a matcher was given in using octal literals (0777) or not (511). To work around this, this change lets you use the cmp matcher for octal strings, for example:

its('mode') { should eq 0766 }
its('mode') { should cmq '0766' }

will give you (on a file that has permissions 0765):

Failures:

  1) File /tmp/file mode should eq 502
     Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }

       expected: 502
            got: 501

       (compared using ==)
     # ./test/integration/default/file_spec.rb:41:in `block (2 levels) in load'

  2) File /tmp/file mode should cmp "0766"
     Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }

       expected: 0766
            got: 0765

       (compared using `cmp` matcher)
     # ./test/integration/default/file_spec.rb:43:in `block (2 levels) in load'

Note that aruba is solving the issue differently: they introduced a matcher for that. It's up for debate, I slightly prefer the cmp matcher.

@srenatus srenatus added the Type: Enhancement Improves an existing feature label Dec 16, 2015
@chris-rock chris-rock removed the Type: Enhancement Improves an existing feature label Dec 16, 2015
@chef-supermarket
Copy link

Hi. Your friendly Curry bot here. Just letting you know that all commit authors have become authorized to contribute. I have added the "Signed CLA" label to this issue so it can easily be found in the future.

@srenatus
Copy link
Contributor Author

🔧 note that the leading 0 is mandatory. its('mode') { should cmp '765'} will fail.

@chris-rock
Copy link
Contributor

Great work. Thanks @srenatus

chris-rock added a commit that referenced this pull request Dec 17, 2015
@chris-rock chris-rock merged commit 0368d1c into master Dec 17, 2015
@chris-rock chris-rock deleted the sr/fix-octal-permissions branch December 17, 2015 11:04
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 this pull request may close these issues.

None yet

3 participants