Class: RSpec::GraphqlMatchers::HaveAField
- Inherits:
-
Object
- Object
- RSpec::GraphqlMatchers::HaveAField
- Defined in:
- lib/rspec/graphql_matchers/have_a_field.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(field_name) ⇒ HaveAField
constructor
A new instance of HaveAField.
- #matches?(graph_object) ⇒ Boolean
- #that_returns(field_type) ⇒ Object (also: #returning, #of_type)
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
#description ⇒ Object
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_message ⇒ Object
24 25 26 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 24 def "expected #{describe_obj(@graph_object)} to #{description}" end |
#matches?(graph_object) ⇒ 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 |