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

Document how to do negative tests for parameter content #57

Closed
incase opened this issue Oct 15, 2012 · 1 comment
Closed

Document how to do negative tests for parameter content #57

incase opened this issue Oct 15, 2012 · 1 comment
Milestone

Comments

@incase
Copy link

incase commented Oct 15, 2012

Hi-

I assume this is already possible, but it is not documented how this should work.

Today a coworker wrote a class that uses a template to set the content of a file. The template has basically this near the bottom of the file:

<% if is_laptop do %>whatever<% end %>

Now, in his rspec tests, he would like to test that with is_laptop set to false, "whatever" does not occur in the content parameter of the file resource.

I would have expected
should contain_file('/etc/a').without_content(/whatever/)
to check that the file is set, with content not containing anything matching 'whatever'. However, the without_content matcher accepts the argument, but basically discards it, testing for content to be undefined. Which it isn't.

should_not contain_file('/etc/a').with_content(/whatever/)

seems to work, but it seems counter-intuitive, especially since it also reports no problem when the file isn't there at all. So the full test today reads like this:

should_not contain_file('/etc/a').with_content(/whatever/)
should contain_file('/etc/a')

Which really looks weird and not very comprehensible.

Proposal:
Change without matcher to check for content to be undefined if no parameter passed (current behaviour), but make it check that the parameter is either undefined or not matching the parameter.

So that in the above example
should contain_file('/etc/a').without_content(/whatever/)
would make sure that
a) the file resource '/etc/a' is defined
b) the resource has a parameter content that doesn't match /whatever/ (by being undefined or having a content that is not matching the regexp.

Regards,
Sven

@rodjek
Copy link
Owner

rodjek commented Dec 5, 2013

without_* tests now check for the absence of the value passed to it, and the documentation has been updated accordingly.

@rodjek rodjek closed this as completed Dec 5, 2013
@rodjek rodjek modified the milestones: 0.2.0, 1.0.0 Sep 29, 2017
ekohl pushed a commit to ekohl/rspec-puppet that referenced this issue Jul 14, 2023
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

No branches or pull requests

2 participants