Sha256: ba024623a4f9300047c9cf7ca7c6c33d0ce6dafb2f6750dbbd1a0b0f6b3bb80b

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require_relative 'base_matcher'
require 'pry'
module RSpec
  module GraphqlMatchers
    class AcceptArguments < BaseMatcher
      attr_reader :actual_field, :expected_args

      def initialize(expected_args)
        @expected_args = expected_args
      end

      def matches?(actual_field)
        @actual_field = actual_field

        @expected_args.all? do |arg_name, arg_type|
          matches_argument?(arg_name, arg_type)
        end
      end

      def failure_message
        "expected field '#{member_name(actual_field)}' to accept arguments "\
        "#{describe_arguments(expected_args)}"
      end

      def description
        "accept arguments #{describe_arguments(expected_args)}"
      end

      private

      def matches_argument?(arg_name, arg_type)
        actual_arg = actual_field.arguments[arg_name.to_s]

        actual_arg && types_match?(actual_arg.type, arg_type)
      end

      def describe_arguments(what_args)
        what_args.sort.map do |arg_name, arg_type|
          "#{arg_name}(#{arg_type})"
        end.join(', ')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-graphql_matchers-1.0.0.pre.0.1 lib/rspec/graphql_matchers/accept_arguments.rb