Skip to content

Commit

Permalink
Add support for underscored argument name in accept_argument
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyArra committed May 2, 2020
1 parent 051a510 commit 3f3bbef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rspec/graphql_matchers/accept_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
16 changes: 16 additions & 0 deletions spec/rspec/accept_argument_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 3f3bbef

Please # to comment.