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_deprecation_reason(expected_reason = nil) ⇒ Object
- #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.
13 14 15 16 17 18 19 20 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 13 def initialize(expected_field_name, fields = :fields) @expected_field_name = expected_field_name.to_s @expected_camel_field_name = GraphQL::Schema::Member::BuildType.camelize( @expected_field_name ) @fields = fields.to_sym @expectations = [] end |
Instance Method Details
#description ⇒ Object
72 73 74 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 72 def description ["define field `#{@expected_field_name}`"].concat(descriptions).join(', ') end |
#failure_message ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 63 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
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 22 def matches?(graph_object) @graph_object = graph_object 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
34 35 36 37 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 34 def that_returns(expected_field_type) @expectations << HaveAFieldMatchers::OfType.new(expected_field_type) self end |
#with_deprecation_reason(expected_reason = nil) ⇒ Object
58 59 60 61 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 58 def with_deprecation_reason(expected_reason = nil) @expectations << HaveAFieldMatchers::WithDeprecationReason.new(expected_reason) self end |
#with_hash_key(expected_hash_key) ⇒ Object
47 48 49 50 51 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 47 def with_hash_key(expected_hash_key) @expectations << HaveAFieldMatchers::WithHashKey.new(expected_hash_key) self end |
#with_metadata(expected_metadata) ⇒ Object
53 54 55 56 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 53 def () @expectations << HaveAFieldMatchers::WithMetadata.new() self end |
#with_property(expected_property_name) ⇒ Object
42 43 44 45 |
# File 'lib/rspec/graphql_matchers/have_a_field.rb', line 42 def with_property(expected_property_name) @expectations << HaveAFieldMatchers::WithProperty.new(expected_property_name) self end |