Sha256: b06ec5da5f43adbb48ebcb7bef79d0e9aaa8a49728a07de9e8df284ebaaf5acd

Contents?: true

Size: 815 Bytes

Versions: 2

Compression:

Stored size: 815 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
          end

          # Class-based api
          actual_field.method_sym
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-graphql_matchers-1.0.1 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb
rspec-graphql_matchers-1.0 lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb