Sha256: be2b8aa58c5140e1a40fd09021b814cba9c827c5aabb74b2b7f169c28ebac044

Contents?: true

Size: 805 Bytes

Versions: 2

Compression:

Stored size: 805 Bytes

Contents

module WildcardMatchers
  module Matchers
    # RSpeck::Mocks has hash_including
    def hash_includes(*args)
      HashIncludes.new(args)
    end

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

        hash_to_match = {}
        hash_to_match = expectation.pop if expectation.last.is_a?(Hash)

        expectation.each do |key|
          errors << "#{position}: expect #{actual} to have key #{key}" unless actual.has_key?(key)
        end

        hash_to_match.each do |key, value|
          errors.push(*self.class.superclass.check_errors(actual[key], value, position + "[#{key.inspect}]"))
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wildcard_matchers-0.1.1 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.1.0 lib/wildcard_matchers/matchers/hash_includes.rb