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)
- #with_hash_key(expected_hash_key) ⇒ Object
- #with_metadata(expected_metadata) ⇒ Object
- #with_property(expected_property_name) ⇒ Object
Constructor Details
#initialize(expected_field_name, fields = :fields) ⇒ HaveAField
Returns a new instance of HaveAField.
12 13 14 15 16 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 12 def initialize(expected_field_name, fields = :fields) @expected_field_name = expected_field_name.to_s @fields = fields.to_sym @expectations = [] end |
Instance Method Details
#description ⇒ Object
64 65 66 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 64 def description ["define field `#{@expected_field_name}`"].concat(descriptions).join(', ') end |
#failure_message ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 55 def base_msg = "expected #{member_name(@graph_object)} " \ "to define field `#{@expected_field_name}`" \ return "#{base_msg} #{.join(', ')}" if @actual_field "#{base_msg} but no field was found with that name" end |
#matches?(graph_object) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 18 def matches?(graph_object) @graph_object = graph_object @actual_field = field_collection[@expected_field_name] return false if @actual_field.nil? @results = @expectations.reject do |matcher| matcher.matches?(@actual_field) end @results.empty? end |
#that_returns(expected_field_type) ⇒ Object Also known as: returning, of_type
31 32 33 34 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 31 def that_returns(expected_field_type) @expectations << HaveAFieldMatchers::OfType.new(expected_field_type) self end |
#with_hash_key(expected_hash_key) ⇒ Object
44 45 46 47 48 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 44 def with_hash_key(expected_hash_key) @expectations << HaveAFieldMatchers::WithHashKey.new(expected_hash_key) self end |
#with_metadata(expected_metadata) ⇒ Object
50 51 52 53 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 50 def () @expectations << HaveAFieldMatchers::WithMetadata.new() self end |
#with_property(expected_property_name) ⇒ Object
39 40 41 42 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 39 def with_property(expected_property_name) @expectations << HaveAFieldMatchers::WithProperty.new(expected_property_name) self end |