Sha256: f1455e12d0cd1aeb77b2602522405186621e6ea9cbee94ba056d415854dba6f3

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
rspec-graphql_matchers-1.3.0 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb
rspec-graphql_matchers-1.2.1 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb
rspec-graphql_matchers-1.2 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb
rspec-graphql_matchers-1.1 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb