Sha256: 99e2c19506e4317e86563766fd16cd707e72de37d6a91ff3400850244c50425d

Contents?: true

Size: 1.26 KB

Versions: 618

Compression:

Stored size: 1.26 KB

Contents

module ContainmentMatchers
  class ContainClass
    def initialize(containee)
      @containee = containee
    end

    def in(container)
      @container = container
      self
    end

    def matches?(catalog)
      @catalog = catalog

      raise ArgumentError, "You must set the container using #in" unless @container

      @container_resource = catalog.resource("Class", @container)
      @containee_resource = catalog.resource("Class", @containee)

      if @containee_resource && @container_resource
        catalog.edge?(@container_resource, @containee_resource)
      else
        false
      end
    end

    def failure_message
      message = "Expected #{@catalog.to_dot} to contain Class #{@containee.inspect} inside of Class #{@container.inspect} but "

      missing = []
      if @container_resource.nil?
        missing << @container
      end
      if @containee_resource.nil?
        missing << @containee
      end

      if ! missing.empty?
        message << "the catalog does not contain #{missing.map(&:inspect).join(' or ')}"
      else
        message << "no containment relationship exists"
      end

      message
    end
  end

  # expect(catalog).to contain_class(containee).in(container)
  def contain_class(containee)
    ContainClass.new(containee)
  end
end

Version data entries

618 entries across 618 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/lib/matchers/containment_matchers.rb
puppet-8.3.0-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.3.0-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.3.0-universal-darwin spec/lib/matchers/containment_matchers.rb
puppet-8.4.0 spec/lib/matchers/containment_matchers.rb
puppet-8.4.0-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.4.0-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.4.0-universal-darwin spec/lib/matchers/containment_matchers.rb
puppet-7.28.0 spec/lib/matchers/containment_matchers.rb
puppet-7.28.0-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-7.28.0-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-7.28.0-universal-darwin spec/lib/matchers/containment_matchers.rb
puppet-8.3.1 spec/lib/matchers/containment_matchers.rb
puppet-8.3.1-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.3.1-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-8.3.1-universal-darwin spec/lib/matchers/containment_matchers.rb
puppet-7.27.0 spec/lib/matchers/containment_matchers.rb
puppet-7.27.0-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-7.27.0-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-7.27.0-universal-darwin spec/lib/matchers/containment_matchers.rb