describe file('/etc/checkfiles/server.cfg') do
its(:content) {
should contain("\/usr\/lib64\/nagios\/plugins\/check_procs -w 150 -c 200")
.after(/command\[check_total_procs\]\=/)
}
end
I'm using contain matcher like this code, but it will be obsoleted. There is so many lines in 'server.cfg' and I want to check only 1line. How can I make same working code without contain matcher?
The docs note that:
Instead of
contain
, you can useits(:content)
and any standard rspec matchers. The matchercontain
will be obsoleted.
I am inclined to say that this change may not have been properly thought out by the maintainer, and you might suggest to him that this feature should not in fact be deprecated.
With that said, though, it is easy enough to solve this problem just using regex:
describe file('/etc/checkfiles/server.cfg') do
its(:content) {
should match /command\[check_total_procs].*check_procs -w 150 -c 200/m
}
end
The key insight there being use of multiline regex //m
, allowing you to say that one string comes after another in the file.