Sha256: 9ed435fbddc8fa0dd4c00e05d394e7b399f745f3364824e076271200579390e8

Contents?: true

Size: 1.84 KB

Versions: 612

Compression:

Stored size: 1.84 KB

Contents

module Matchers; module Resource
  extend RSpec::Matchers::DSL

  matcher :have_resource do |expected_resource|
    def resource_match(expected_resource, actual_resource)
      matched = true
      failures = []

      if actual_resource.ref != expected_resource
        matched = false
        failures << "expected #{expected_resource} but was #{actual_resource.ref}"
      end

      @params ||= {}
      @params.each do |name, value|
        case value
        when RSpec::Matchers::DSL::Matcher
          if !value.matches?(actual_resource[name])
            matched = false
            failures << "expected #{name} to match '#{value.description}' but was '#{actual_resource[name]}'"
          end
        else
          if actual_resource[name] != value
            matched = false
            failures << "expected #{name} to be '#{value}' but was '#{actual_resource[name]}'"
          end
        end
      end
      @mismatch = failures.join("\n")

      matched
    end

    match do |actual_catalog|
      @mismatch = ""
      if resource = actual_catalog.resource(expected_resource)
        resource_match(expected_resource, resource)
      else
        @mismatch = "expected #{@actual.to_dot} to include #{expected_resource}"
        false
      end
    end

    chain :with_parameter do |name, value|
      @params ||= {}
      @params[name] = value
    end

    def failure_message
      @mismatch
    end
  end


  matcher :be_resource do |expected_resource|
    def resource_match(expected_resource, actual_resource)
      if actual_resource.ref == expected_resource
        true
      else
        @mismatch = "expected #{expected_resource} but was #{actual_resource.ref}"
        false
      end
    end

    match do |actual_resource|
      resource_match(expected_resource, actual_resource)
    end

    def failure_message
      @mismatch
    end
  end

end; end

Version data entries

612 entries across 612 versions & 1 rubygems

Version Path
puppet-7.24.0 spec/lib/matchers/resource.rb
puppet-7.24.0-x86-mingw32 spec/lib/matchers/resource.rb
puppet-7.24.0-x64-mingw32 spec/lib/matchers/resource.rb
puppet-7.24.0-universal-darwin spec/lib/matchers/resource.rb
puppet-7.23.0 spec/lib/matchers/resource.rb
puppet-7.23.0-x86-mingw32 spec/lib/matchers/resource.rb
puppet-7.23.0-x64-mingw32 spec/lib/matchers/resource.rb
puppet-7.23.0-universal-darwin spec/lib/matchers/resource.rb
puppet-7.22.0 spec/lib/matchers/resource.rb
puppet-7.22.0-x86-mingw32 spec/lib/matchers/resource.rb
puppet-7.22.0-x64-mingw32 spec/lib/matchers/resource.rb
puppet-7.22.0-universal-darwin spec/lib/matchers/resource.rb
puppet-6.29.0 spec/lib/matchers/resource.rb
puppet-6.29.0-x86-mingw32 spec/lib/matchers/resource.rb
puppet-6.29.0-x64-mingw32 spec/lib/matchers/resource.rb
puppet-6.29.0-universal-darwin spec/lib/matchers/resource.rb
puppet-7.21.0 spec/lib/matchers/resource.rb
puppet-7.21.0-x86-mingw32 spec/lib/matchers/resource.rb
puppet-7.21.0-x64-mingw32 spec/lib/matchers/resource.rb
puppet-7.21.0-universal-darwin spec/lib/matchers/resource.rb