Sha256: be6526c4b167f8219c05e39831ca780603ec506acd2a38fdbb3530725ff7827c

Contents?: true

Size: 1.28 KB

Versions: 63

Compression:

Stored size: 1.28 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_for_should
      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

63 entries across 63 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/lib/matchers/containment_matchers.rb
puppet-3.8.7-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.7-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.6 spec/lib/matchers/containment_matchers.rb
puppet-3.8.6-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.6-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.5 spec/lib/matchers/containment_matchers.rb
puppet-3.8.5-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.5-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.4 spec/lib/matchers/containment_matchers.rb
puppet-3.8.4-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.4-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.3 spec/lib/matchers/containment_matchers.rb
puppet-3.8.3-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.3-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.2 spec/lib/matchers/containment_matchers.rb
puppet-3.8.2-x86-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.2-x64-mingw32 spec/lib/matchers/containment_matchers.rb
puppet-3.8.1 spec/lib/matchers/containment_matchers.rb
puppet-3.8.1-x86-mingw32 spec/lib/matchers/containment_matchers.rb