From 3f3bbef097b01775fc7edae10699fae59df24d95 Mon Sep 17 00:00:00 2001 From: Tony Arra Date: Fri, 1 May 2020 18:25:33 -0400 Subject: [PATCH] Add support for underscored argument name in accept_argument --- lib/rspec/graphql_matchers/accept_argument.rb | 5 ++++- spec/rspec/accept_argument_matcher_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/rspec/graphql_matchers/accept_argument.rb b/lib/rspec/graphql_matchers/accept_argument.rb index e976b8b..8ed32f5 100644 --- a/lib/rspec/graphql_matchers/accept_argument.rb +++ b/lib/rspec/graphql_matchers/accept_argument.rb @@ -17,12 +17,15 @@ def initialize(expected_arg_name) end @expected_arg_name = expected_arg_name.to_s + @expected_camel_arg_name = GraphQL::Schema::Member::BuildType.camelize( + @expected_arg_name + ) end def matches?(graph_object) @graph_object = graph_object - @actual_argument = field_arguments[@expected_arg_name] + @actual_argument = field_arguments[@expected_arg_name] || field_arguments[@expected_camel_arg_name] return false if @actual_argument.nil? @results = @expectations.select do |matcher| diff --git a/spec/rspec/accept_argument_matcher_spec.rb b/spec/rspec/accept_argument_matcher_spec.rb index db3a2da..302f48a 100644 --- a/spec/rspec/accept_argument_matcher_spec.rb +++ b/spec/rspec/accept_argument_matcher_spec.rb @@ -9,6 +9,18 @@ module RSpec::GraphqlMatchers expect(a_type).to accept_argument(:id) end + it 'passes with the underscored argument name' do + expect(a_type).to accept_argument(:is_test) + end + + it 'passes with the camel cased argument name' do + expect(a_type).to accept_argument(:isTest) + end + + it 'matches a non camelized argument with the underscored argument name' do + expect(a_type).to accept_argument(:not_camelized) + end + it 'fails when the type does not define the expected field' do expect { expect(a_type).to accept_argument(:ids) } .to fail_with( @@ -89,6 +101,8 @@ module RSpec::GraphqlMatchers argument :id, GraphQL::Types::String, required: false argument :other, GraphQL::Types::ID, required: true + argument :is_test, GraphQL::Types::Boolean, required: false + argument :not_camelized, GraphQL::Types::Boolean, required: false, camelize: false end end @@ -102,6 +116,8 @@ module RSpec::GraphqlMatchers argument :id, types.String argument :other, !types.ID + argument :isTest, types.Boolean + argument :not_camelized, types.Boolean end end