Class: RSpec::GraphqlMatchers::AcceptArgument
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::GraphqlMatchers::AcceptArgument
- Defined in:
- lib/rspec/graphql_matchers/accept_argument.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_arg_name) ⇒ AcceptArgument
constructor
A new instance of AcceptArgument.
- #matches?(graph_object) ⇒ Boolean
- #of_type(expected_field_type) ⇒ Object
Constructor Details
#initialize(expected_arg_name) ⇒ AcceptArgument
Returns a new instance of AcceptArgument.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec/graphql_matchers/accept_argument.rb', line 7 def initialize(expected_arg_name) @expectations = [] if expected_arg_name.is_a?(Hash) (expected_arg_name, expected_type) = expected_arg_name.to_a.first of_type(expected_type) warn 'DEPRECATION WARNING: using accept_arguments with a hash will be '\ 'deprecated on the next major release. Use the format ' \ "`accept_argument(:argument_name).of_type('ExpectedType!') instead.`" end @expected_arg_name = expected_arg_name.to_s end |
Instance Method Details
#description ⇒ Object
49 50 51 |
# File 'lib/rspec/graphql_matchers/accept_argument.rb', line 49 def description ["accept argument `#{@expected_arg_name}`"].concat(descriptions).join(', ') end |
#failure_message ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rspec/graphql_matchers/accept_argument.rb', line 40 def base_msg = "expected #{member_name(@graph_object)} " \ "to accept argument `#{@expected_arg_name}`" \ return "#{base_msg} #{.join(', ')}" if @actual_argument "#{base_msg} but no argument was found with that name" end |
#matches?(graph_object) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rspec/graphql_matchers/accept_argument.rb', line 22 def matches?(graph_object) @graph_object = graph_object @actual_argument = field_arguments[@expected_arg_name] return false if @actual_argument.nil? @results = @expectations.select do |matcher| !matcher.matches?(@actual_argument) end @results.empty? end |
#of_type(expected_field_type) ⇒ Object
35 36 37 38 |
# File 'lib/rspec/graphql_matchers/accept_argument.rb', line 35 def of_type(expected_field_type) @expectations << HaveAFieldMatchers::OfType.new(expected_field_type) self end |