Sha256: 63de50a3fb4aa6633130b4fbfa6c0841afca5ae9868a4cdda6f421cffc810ddc

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Sbmt
  module Pact
    module Matchers
      module V4
        class EachKey < Sbmt::Pact::Matchers::Base
          def initialize(key_matchers, template)
            raise MatcherInitializationError, "#{self.class}: #{template} should be a Hash" unless template.is_a?(Hash)
            raise MatcherInitializationError, "#{self.class}: #{key_matchers} should be an Array" unless key_matchers.is_a?(Array)
            raise MatcherInitializationError, "#{self.class}: #{key_matchers} should be instances of Sbmt::Pact::Matchers::Base" unless key_matchers.all?(Sbmt::Pact::Matchers::Base)
            raise MatcherInitializationError, "#{self.class}: #{key_matchers} size should be greater than 0" unless key_matchers.size > 0

            super(spec_version: Sbmt::Pact::Matchers::PACT_SPEC_V4, kind: "each-key", template: template, opts: {rules: key_matchers})
          end

          def as_plugin
            @opts[:rules].map do |matcher|
              "eachKey(#{matcher.as_plugin})"
            end.join(", ")
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbmt-pact-0.12.2 lib/sbmt/pact/matchers/v4/each_key.rb
sbmt-pact-0.12.1 lib/sbmt/pact/matchers/v4/each_key.rb
sbmt-pact-0.12.0 lib/sbmt/pact/matchers/v4/each_key.rb