class RSpec::GraphqlMatchers::BeOfType

Attributes

expected[R]
sample[R]

Public Class Methods

new(expected) click to toggle source
# File lib/rspec/graphql_matchers/be_of_type.rb, line 10
def initialize(expected)
  @expected = expected
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/graphql_matchers/be_of_type.rb, line 24
def description
  "be of type '#{expected}'"
end
failure_message() click to toggle source
# File lib/rspec/graphql_matchers/be_of_type.rb, line 19
def failure_message
  "expected field '#{member_name(sample)}' to be of type '#{expected}', " \
  "but it was '#{type_name(sample.type)}'"
end
matches?(actual_sample) click to toggle source
# File lib/rspec/graphql_matchers/be_of_type.rb, line 14
def matches?(actual_sample)
  @sample = to_graphql(actual_sample)
  sample.respond_to?(:type) && types_match?(sample.type, @expected)
end

Private Instance Methods

to_graphql(field_sample) click to toggle source
# File lib/rspec/graphql_matchers/be_of_type.rb, line 30
def to_graphql(field_sample)
  return field_sample unless field_sample.respond_to?(:to_graphql)

  field_sample.to_graphql
end