Class: RSpec::GraphqlMatchers::BeOfType

Inherits:
BaseMatcher show all
Defined in:
lib/rspec/graphql_matchers/be_of_type.rb

Direct Known Subclasses

HaveAFieldMatchers::OfType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ BeOfType

Returns a new instance of BeOfType.



10
11
12
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 10

def initialize(expected)
  @expected = expected
end

Instance Attribute Details

#expectedObject (readonly)

Returns the value of attribute expected.



8
9
10
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 8

def expected
  @expected
end

#sampleObject (readonly)

Returns the value of attribute sample.



8
9
10
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 8

def sample
  @sample
end

Instance Method Details

#descriptionObject



24
25
26
# File 'lib/rspec/graphql_matchers/be_of_type.rb', line 24

def description
  "be of type '#{expected}'"
end

#failure_messageObject



19
20
21
22
# 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) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# 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