class Shoulda::Matchers::Graphql::Fields::WithArguments

Public Class Methods

new(field_name, **args) click to toggle source
# File lib/shoulda/matchers/graphql/fields/with_arguments.rb, line 6
def initialize(field_name, **args)
  super(field_name)
  @arguments = *args
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/graphql/fields/with_arguments.rb, line 32
def description
  args = @arguments.join(", ")
  super + ", with argument(s) #{args}"
end
failure_message() click to toggle source
# File lib/shoulda/matchers/graphql/fields/with_arguments.rb, line 41
def failure_message
  "oops"
end
field_arguments() click to toggle source
# File lib/shoulda/matchers/graphql/fields/with_arguments.rb, line 37
def field_arguments
  @subject.fields[@field_name].instance_variable_get("@own_arguments")
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/graphql/fields/with_arguments.rb, line 11
def matches?(subject)
  super(subject)
  @arguments.map do |k, v|
    tokens = k.to_s.split("_")
    first, *rem = tokens
    rem = rem.map(&:capitalize)
    camelized = first + rem.join
    if field_arguments[camelized].nil?
      return false
    end
    #TODO: additional options checks, refactor into own module
    if !v[:required].nil?
      required = v[:required]
      nullable = field_arguments[camelized].instance_variable_get("@null")
      required == !nullable
    else
      true
    end
  end.all?
end