Method: Specinfra::Command::Base::File.check_contains_within

Defined in:
lib/specinfra/command/base/file.rb

.check_contains_within(file, expected_pattern, from = nil, to = nil) ⇒ Object


58
59
60
61
62
63
64
65
66
# File 'lib/specinfra/command/base/file.rb', line 58

def check_contains_within(file, expected_pattern, from=nil, to=nil)
  from ||= '1'
  to ||= '$'
  sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}"
  sed += " | sed -n 1,#{escape(to)}p" if from != '1' and to != '$'
  checker_with_regexp = check_contains_with_regexp("-", expected_pattern)
  checker_with_fixed = check_contains_with_fixed_strings("-", expected_pattern)
  "#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}"
end