Class: RSpec::GraphqlMatchers::HaveAField
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::GraphqlMatchers::HaveAField
- Defined in:
- lib/rspec/graphql_matchers/have_a_field.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_field_name, fields = :fields) ⇒ HaveAField
constructor
A new instance of HaveAField.
- #matches?(graph_object) ⇒ Boolean
- #that_returns(expected_field_type) ⇒ Object (also: #returning, #of_type)
Constructor Details
#initialize(expected_field_name, fields = :fields) ⇒ HaveAField
Returns a new instance of HaveAField.
6 7 8 9 10 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 6 def initialize(expected_field_name, fields = :fields) @expected_field_name = expected_field_name.to_s @expected_field_type = @graph_object = nil @fields = fields.to_sym end |
Instance Method Details
#description ⇒ Object
32 33 34 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 32 def description "define field `#{@expected_field_name}`" + of_type_description end |
#failure_message ⇒ Object
27 28 29 30 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 27 def "expected #{describe_obj(@graph_object)} to " \ "#{description}, #{explanation}." end |
#matches?(graph_object) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 12 def matches?(graph_object) @graph_object = graph_object @actual_field = field_collection[@expected_field_name] valid_field? && types_match?(@actual_field.type, @expected_field_type) end |
#that_returns(expected_field_type) ⇒ Object Also known as: returning, of_type
19 20 21 22 23 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 19 def that_returns(expected_field_type) @expected_field_type = expected_field_type self end |