You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: