Skip to content

Commit

Permalink
Merge pull request #29 from makketagg/add/underscored-arguments-support
Browse files Browse the repository at this point in the history
Added support of underscored arguments in have_field
  • Loading branch information
khamusa authored Feb 6, 2020
2 parents 6633aa7 + 6672812 commit d92d33c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/graphql_matchers/have_a_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module RSpec
module GraphqlMatchers
class HaveAField < BaseMatcher
def initialize(expected_field_name, fields = :fields)
@expected_field_name = expected_field_name.to_s
@expected_field_name = GraphQL::Schema::Member::BuildType.camelize(expected_field_name.to_s)
@fields = fields.to_sym
@expectations = []
end
Expand Down
2 changes: 1 addition & 1 deletion rspec-graphql_matchers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'graphql', '>= 1.8', '< 2.0'
spec.add_development_dependency 'bundler', '~> 1.12'
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rubocop', '0.71'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'pry', '~> 0'
Expand Down
16 changes: 16 additions & 0 deletions spec/rspec/have_a_field_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ module RSpec::GraphqlMatchers
expect(a_type).to have_a_field(:id)
end

it 'passes with the underscored field name' do
expect(a_type).to have_a_field(:is_test)
end

it 'passes with the camel cased field name' do
expect(a_type).to have_a_field(:isTest)
end

it 'fails when the type does not define the expected field' do
expect { expect(a_type).to have_a_field(:ids) }
.to fail_with(
Expand Down Expand Up @@ -39,12 +47,16 @@ module RSpec::GraphqlMatchers
'strings' do
expect(a_type).to have_a_field(:id).that_returns('ID!')
expect(a_type).to have_a_field('other').that_returns('String')
expect(a_type).to have_a_field(:is_test).of_type('Boolean')
expect(a_type).to have_a_field(:isTest).of_type('Boolean')
end

it 'passes when the type defines the field with correct type as ' \
'graphql objects' do
expect(a_type).to have_a_field(:id).that_returns('ID!')
expect(a_type).to have_a_field('other').of_type(types.String)
expect(a_type).to have_a_field(:is_test).of_type(types.Boolean)
expect(a_type).to have_a_field(:isTest).of_type(types.Boolean)
end

it 'fails when the type defines a field of the wrong type' do
Expand Down Expand Up @@ -97,6 +109,7 @@ module RSpec::GraphqlMatchers

field :id, types.ID, null: false
field :other, types.String, hash_key: :other_on_hash, null: true
field :is_test, types.Boolean, null: true
end
end

Expand All @@ -109,6 +122,7 @@ module RSpec::GraphqlMatchers
graphql_name 'ActualInterface'

field :other, types.String, hash_key: :other_on_hash, null: true
field :is_test, types.Boolean, null: true
end

Class.new(GraphQL::Schema::Object) do
Expand Down Expand Up @@ -137,6 +151,8 @@ module RSpec::GraphqlMatchers
field :other,
types.String,
hash_key: :other_on_hash

field :isTest, types.Boolean
end
end

Expand Down

0 comments on commit d92d33c

Please # to comment.