From ce2bf44605e8d7df116da82662a0b8b13d428a27 Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Thu, 19 Dec 2019 22:03:49 +0300 Subject: [PATCH 1/7] Added support of underscored arguments in have_field --- lib/rspec/graphql_matchers/have_a_field.rb | 3 ++- spec/rspec/have_a_field_matcher_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/rspec/graphql_matchers/have_a_field.rb b/lib/rspec/graphql_matchers/have_a_field.rb index 84de00b..722637a 100644 --- a/lib/rspec/graphql_matchers/have_a_field.rb +++ b/lib/rspec/graphql_matchers/have_a_field.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'graphql/schema/member/build_type' require_relative 'base_matcher' require_relative './have_a_field_matchers/of_type' require_relative './have_a_field_matchers/with_property' @@ -10,7 +11,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 diff --git a/spec/rspec/have_a_field_matcher_spec.rb b/spec/rspec/have_a_field_matcher_spec.rb index b0e92b4..016e105 100644 --- a/spec/rspec/have_a_field_matcher_spec.rb +++ b/spec/rspec/have_a_field_matcher_spec.rb @@ -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( @@ -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 @@ -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 @@ -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 @@ -137,6 +151,8 @@ module RSpec::GraphqlMatchers field :other, types.String, hash_key: :other_on_hash + + field :isTest, types.Boolean end end From 7315b9cb133aaae8c71e067e92b59e7cfa6d5756 Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Thu, 19 Dec 2019 22:08:04 +0300 Subject: [PATCH 2/7] Removed a line with graphql module --- lib/rspec/graphql_matchers/have_a_field.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/rspec/graphql_matchers/have_a_field.rb b/lib/rspec/graphql_matchers/have_a_field.rb index 722637a..e190c80 100644 --- a/lib/rspec/graphql_matchers/have_a_field.rb +++ b/lib/rspec/graphql_matchers/have_a_field.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'graphql/schema/member/build_type' require_relative 'base_matcher' require_relative './have_a_field_matchers/of_type' require_relative './have_a_field_matchers/with_property' From 454ea1f17c299eba2bf2497b6cc35777870f4763 Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Thu, 19 Dec 2019 22:39:07 +0300 Subject: [PATCH 3/7] Try to fix with bundler issue --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 67a731d..e89c0f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ sudo: false language: ruby rvm: - 2.3.1 -before_install: gem install bundler -v 1.12.3 +before_install: + - gem install bundler -v 1.12.3 + - bundle _1.12.3_ install script: bundle exec rspec matrix: include: From 44093642caf13a73de04f39607b1ffe020b021ca Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Thu, 19 Dec 2019 22:46:36 +0300 Subject: [PATCH 4/7] Rollback travis config --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e89c0f9..67a731d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,7 @@ sudo: false language: ruby rvm: - 2.3.1 -before_install: - - gem install bundler -v 1.12.3 - - bundle _1.12.3_ install +before_install: gem install bundler -v 1.12.3 script: bundle exec rspec matrix: include: From 91480a7dfb4416e176a9df1d7f40eaee841ef6d8 Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Mon, 3 Feb 2020 17:42:52 +0300 Subject: [PATCH 5/7] Updated travisci config --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 67a731d..103d9c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ sudo: false language: ruby rvm: - 2.3.1 -before_install: gem install bundler -v 1.12.3 +before_install: + - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true + - gem install bundler -v '< 2' script: bundle exec rspec matrix: include: From 949b889b8aa60f4b3bae32f0eda74f86c1626bce Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Mon, 3 Feb 2020 18:16:19 +0300 Subject: [PATCH 6/7] Reverted ci config --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 103d9c6..67a731d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,7 @@ sudo: false language: ruby rvm: - 2.3.1 -before_install: - - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true - - gem install bundler -v '< 2' +before_install: gem install bundler -v 1.12.3 script: bundle exec rspec matrix: include: From 6672812f43fc451211ad8d5ffa7cdda1d52fbe81 Mon Sep 17 00:00:00 2001 From: Imir Kiyamov Date: Mon, 3 Feb 2020 18:23:55 +0300 Subject: [PATCH 7/7] Upgraded bundler version to 2.x --- rspec-graphql_matchers.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rspec-graphql_matchers.gemspec b/rspec-graphql_matchers.gemspec index 1959fc4..d575015 100644 --- a/rspec-graphql_matchers.gemspec +++ b/rspec-graphql_matchers.gemspec @@ -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'