0
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?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
Harley G.
  • 23
  • 4
  • The `contain` matcher is a custom extension to Serverspec with the custom chain `after`: https://github.com/mizzy/serverspec/blob/5cb12294775e02b53ff902687730bd279ff89065/lib/serverspec/matcher/contain.rb#L20. If you updated to the modern syntax/usage, then you would lose the `after` chain. Is that ok? – Matthew Schuchard Feb 21 '20 at 14:55

1 Answers1

0

The docs note that:

Instead of contain, you can use its(:content) and any standard rspec matchers. The matcher contain 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.

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97