class RSpec::GraphqlMatchers::Implement

Public Class Methods

new(interfaces) click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 6
def initialize(interfaces)
  @expected = interfaces.map {|interface| interface_name(interface) }
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 28
def description
  "implement #{@expected.join(', ')}"
end
failure_message() click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 16
def failure_message
  message  = "expected interfaces: #{@expected.join(', ')}\n"
  message += "actual interfaces:   #{@actual.join(', ')}"
  message
end
failure_message_when_negated() click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 22
def failure_message_when_negated
  message  = "unexpected interfaces: #{@expected.join(', ')}\n"
  message += "actual interfaces:     #{@actual.join(', ')}"
  message
end
matches?(graph_object) click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 10
def matches?(graph_object)
  @graph_object = graph_object
  @actual = actual
  @expected.all? { |name| @actual.include?(name) }
end

Private Instance Methods

actual() click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 34
def actual
  if @graph_object.respond_to?(:interfaces)
    return @graph_object.interfaces.map do |interface|
      interface_name(interface)
    end
  end

  raise "Invalid object #{@graph_object} provided to #{matcher_name} " \
    'matcher. It does not seem to be a valid GraphQL object type.'
end
interface_name(interface) click to toggle source
# File lib/rspec/graphql_matchers/implement.rb, line 45
def interface_name(interface)
  return interface.graphql_name if interface.respond_to?(:graphql_name)

  interface.to_s
end