serverspec/specinfra — pull request #191 by mattjmorrison (2014-08-15 17:02:20+00:00)
Title: Added more strict check on `check_file_contain_within`

I believe I have a solution that will address [this issue](https://github.com/serverspec/serverspec/issues/467), but I need some help with the tests. Right out of the gates I noticed the `integration-tests` submodule but I couldn't get `rake spec` to work. Is there any special set up that I need to do to get that working? I went ahead and submitted what I think is a good solution, but I would still like to add some tests to verify and ensure that there are no regressions due to this change.

`check_file_contain_within` uses `sed`'s range, however when the end
portion of the range is not found in the file the end of the file will
be the end of the range. This can cause false positives when an end is
missing.

For example:

```

StartServers 5
```

would currently pass the following assertion in [serverspec](https://github.com/serverspec/)

```
it { should contain('StartServers 5').from(/^/).to(/^<\/IfModule>/) }
```

I would expect this to fail due to the fact that `` does not
exist in the example above.

The solution that I propose is adding an additional check that will
verify the range using `sed` as it currently does plus doing the
equivalent of what the `contain().before()` does on the closing tag.