serverspec/specinfra — pull request #200 by mattjmorrison (2014-08-21 15:06:08+00:00)
Title: This fixes a regression with `check_file_contain_within`

A apologize in advance for not providing any tests with this PR, I took another stab at it but I was getting vagrant errors: "Vagrant: * Unknown configuration section 'omnibus'". I did write tests and verified that this works correctly - I actually used the tests in the serverspec repo and used `gem open` to make this change. (I can submit another PR for that repo that contains the updated tests).

With [this PR](https://github.com/serverspec/specinfra/pull/191) a
regression was introduced with the `before` and `after` matchers when
they aren't being used together.

With PR 191 the following:

```
it { should contain('rspec').before(/^end/) }
```

would have resulted in:

```
sed -n 1,/\\^end/p Gemfile | sed -n 1,/\\^end/p | grep -qs -- rspec - || sed -n 1,/\\^end/p Gemfile | sed -n 1,/\\^end/p | grep -qFs -- rspec -
```

as well as:

```
it { should contain('rspec').after(/^group :test do/) }
```

would result in:

```
sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | sed -n 1,\\$p | grep -qs -- rspec - || sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | sed -n 1,\\$p | grep -qFs -- rspec -
```

Notice in both scenarios the `sed` command is unnecessarily duplicated.

While neither of these should actually cause an assertion to pass when
it should fail, they also do not add anything for either situation.