Sha256: 8510a5c31d843adb9b3e52a3d6a0f176d66fdda04ba487e8342ec7656264f766

Contents?: true

Size: 659 Bytes

Versions: 59

Compression:

Stored size: 659 Bytes

Contents

RSpec::Matchers.define :contain do |pattern|
  match do |resource|
    if resource.is_a?(String)
      resource.match(Regexp.new([@from, pattern, @to].compact.join.gsub('/', '.*'), Regexp::MULTILINE))
    else
      resource.contain(pattern, @from, @to)
    end
  end

  # for contain(pattern).from(/A/).to(/B/)
  chain :from do |from|
    @from = Regexp.new(from).inspect
  end

  chain :to do |to|
    @to = Regexp.new(to).inspect
  end

  # for contain(pattern).after(/A/)
  chain :after do |after|
    @from = Regexp.new(after).inspect
  end

  # for contain(pattern).before(/B/)
  chain :before do |before|
    @to = Regexp.new(before).inspect
  end
end

Version data entries

59 entries across 59 versions & 3 rubygems

Version Path
serverspec-2.38.0 lib/serverspec/matcher/contain.rb
serverspec-2.37.2 lib/serverspec/matcher/contain.rb
serverspec-2.37.1 lib/serverspec/matcher/contain.rb
serverspec-2.37.0 lib/serverspec/matcher/contain.rb
serverspec-2.36.1 lib/serverspec/matcher/contain.rb
serverspec-2.36.0 lib/serverspec/matcher/contain.rb
serverspec-2.35.0 lib/serverspec/matcher/contain.rb
serverspec-2.34.0 lib/serverspec/matcher/contain.rb
serverspec-2.33.0 lib/serverspec/matcher/contain.rb
serverspec-2.32.0 lib/serverspec/matcher/contain.rb
serverspec-2.31.1 lib/serverspec/matcher/contain.rb
serverspec-2.31.0 lib/serverspec/matcher/contain.rb
serverspec-2.30.1 lib/serverspec/matcher/contain.rb
serverspec-2.30.0 lib/serverspec/matcher/contain.rb
serverspec-2.29.2 lib/serverspec/matcher/contain.rb
serverspec-2.29.1 lib/serverspec/matcher/contain.rb
serverspec-2.29.0 lib/serverspec/matcher/contain.rb
serverspec-2.28.0 lib/serverspec/matcher/contain.rb
serverspec-2.27.0 lib/serverspec/matcher/contain.rb
serverspec-2.26.0 lib/serverspec/matcher/contain.rb