Sha256: b612c5713f18ad8be27ce0cc6523b987f36a7b80a9f5cd17c6e67052116f4e24

Contents?: true

Size: 784 Bytes

Versions: 9

Compression:

Stored size: 784 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|
              errors.push(*self.class.superclass.check_errors(actual[key], value, position + "[#{key.inspect}]"))
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wildcard_matchers-0.9.1 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.9.0 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.4.0 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.3.1 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.3.0 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.2.1 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.2.0 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.1.8 lib/wildcard_matchers/matchers/hash_includes.rb
wildcard_matchers-0.1.7 lib/wildcard_matchers/matchers/hash_includes.rb