Sha256: fba989c2f0a4033149babb84035790a5af4941f9ee4fc39b49218689b8e3cbdd

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module RSpec
  module GraphqlMatchers
    module HaveAFieldMatchers
      class WithHashKey
        def initialize(expected_hash_key)
          @expected_hash_key = expected_hash_key
        end

        def description
          "with hash key `#{@expected_hash_key}`"
        end

        def matches?(actual_field)
          @actual_hash_key = get_hash_key(actual_field)
          @actual_hash_key == @expected_hash_key.to_sym
        end

        def failure_message
          "#{description}, but it was `#{@actual_hash_key}`"
        end

        private

        def get_hash_key(actual_field)
          if actual_field.respond_to?(:hash_key)
            return actual_field.hash_key.to_sym if actual_field.hash_key
          end

          actual_field.metadata[:type_class].method_sym
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-graphql_matchers-1.3.1 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb