I recommend ```%r{}``` with which i think you can simplify to:
```ruby
with_content(%r{^\s+modulepath\s+= /etc/puppet/environments/foo/modules:/etc/puppet/environments/common:/usr/share/puppet/modules$}).
```