Sha256: 2d2ea9443cd605a9b960b679882678a7ec32e29bd2fcfa8d0025cbd154593977

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

module WildcardMatchers
  module Matchers
    # RSpeck::Mocks has hash_including
    define_wildcard_matcher(:hash_includes)

    class HashIncludes < ::WildcardMatchers::WildcardMatcher
      protected
      def wildcard_match(actual)
        unless actual && actual.is_a?(Hash)
          errors.push "#{position}: expect #{actual.inspect} to Hash"
          return
        end

        expectation.each do |key|
          unless key.is_a?(Hash)
            errors << "#{position}: expect #{actual} to have key #{key}" unless actual.has_key?(key)
          else
            key.each do |key, value|
              unless actual.has_key?(key)
                errors << "#{position}: expect #{actual} to have key #{key}"
              else
                errors.push(*self.class.superclass.check_errors(actual[key], value, position + "[#{key.inspect}]"))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wildcard_matchers-0.9.2 lib/wildcard_matchers/matchers/hash_includes.rb