Class: RSpec::GraphqlMatchers::HaveAField

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/graphql_matchers/have_a_field.rb

Instance Method Summary collapse

Constructor Details

#initialize(field_name) ⇒ HaveAField

Returns a new instance of HaveAField.



4
5
6
7
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 4

def initialize(field_name)
  @field_name = field_name.to_s
  @field_type = @graph_object = nil
end

Instance Method Details

#descriptionObject



28
29
30
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 28

def description
  "define field `#{@field_name}`" + of_type_description
end

#failure_messageObject



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

def failure_message
  "expected #{describe_obj(@graph_object)} to #{description}"
end

#matches?(graph_object) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 9

def matches?(graph_object)
  @graph_object = graph_object

  actual_field = @graph_object.fields[@field_name]
  actual_field && types_match?(@field_type, actual_field.type)
end

#that_returns(field_type) ⇒ Object Also known as: returning, of_type



16
17
18
19
20
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 16

def that_returns(field_type)
  @field_type = field_type

  self
end