Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support of underscored arguments in have_field #29

Merged
merged 7 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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