rspec-graphql_matchers 1.3.1 → 2.0.0.pre.rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +3 -3
- data/CHANGELOG.md +38 -0
- data/Gemfile +0 -8
- data/README.md +11 -40
- data/lib/rspec/graphql_matchers/accept_argument.rb +6 -2
- data/lib/rspec/graphql_matchers/accept_arguments.rb +1 -1
- data/lib/rspec/graphql_matchers/base_matcher.rb +1 -1
- data/lib/rspec/graphql_matchers/be_of_type.rb +4 -3
- data/lib/rspec/graphql_matchers/have_a_field.rb +9 -6
- data/lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb +1 -1
- data/lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb +5 -1
- data/lib/rspec/graphql_matchers/matchers.rb +2 -2
- data/lib/rspec/graphql_matchers/types_helper.rb +13 -1
- data/lib/rspec/graphql_matchers/version.rb +1 -1
- data/rspec-graphql_matchers.gemspec +1 -4
- metadata +11 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 984e7d05766f0502ee910f99f522cd81a873b87a9c64ba13b7b1441602c65e51
|
4
|
+
data.tar.gz: d21699dc04dde4843a7d9a109674f8b9d208b35adb39ccfa5a7c2560b209ce4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a1ab2cb2da43f52f17080065d9a4616459a4ce23b39bb3ea39259cc35599e0325c5fd90077d62e785262de19c92512e95c41742d62f5cd8e9372d7a834ce3a2
|
7
|
+
data.tar.gz: 9524fb181330f10eeb4dc7c7eb31888c48a3c97003c7f47579749a00b59672b2148b59d2579ee75a1ea11dcab4626641ce51b7986e714dc177290ea4a0c2ca73
|
data/.github/workflows/rspec.yml
CHANGED
@@ -2,7 +2,7 @@ name: RSpec
|
|
2
2
|
|
3
3
|
# Controls when the action will run. Triggers the workflow on push or pull request
|
4
4
|
# events but only for the master branch
|
5
|
-
on: [
|
5
|
+
on: [push, pull_request]
|
6
6
|
|
7
7
|
jobs:
|
8
8
|
# This workflow contains a single job "rspec"
|
@@ -12,7 +12,7 @@ jobs:
|
|
12
12
|
|
13
13
|
strategy:
|
14
14
|
matrix:
|
15
|
-
ruby_version: [
|
15
|
+
ruby_version: [2.6, 2.7, 3.0, 3.1, 3.2]
|
16
16
|
|
17
17
|
# Steps represent a sequence of tasks that will be executed as part of the job
|
18
18
|
steps:
|
@@ -36,6 +36,6 @@ jobs:
|
|
36
36
|
key: ${{ runner.os }}-${{ matrix.ruby_version }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
37
37
|
restore-keys: |
|
38
38
|
${{ runner.os }}-${{ matrix.ruby_version }}-gems-
|
39
|
-
|
39
|
+
|
40
40
|
- name: Run RSpec
|
41
41
|
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,44 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.0 (April 16th, 2023)
|
4
|
+
|
5
|
+
- Adds compatibility with graphql-ruby 2.0+. If you're still using an earlier version, you should stick to 1.4.x.
|
6
|
+
|
7
|
+
### Deprecations
|
8
|
+
|
9
|
+
- The usage of the `#types` helper when writing tests (if you're not including `RSpec::GraphqlMatchers::TypesHelper` anywhere, you shoudn't have to change anything). Use `GraphQL::Types::<TYPE_NAME>` instead
|
10
|
+
- The usage of type instances as expected value for a type comparison is deprecated. Instead,
|
11
|
+
use the string that represents the type specification. Examples:
|
12
|
+
|
13
|
+
```
|
14
|
+
# Bad - These are deprecated:
|
15
|
+
expect(a_type).to have_a_field(:lorem).of_type(GraphQL::Types::ID)
|
16
|
+
expect(a_type).to have_a_field(:lorem).of_type(Types::MyCustomType)
|
17
|
+
|
18
|
+
# Good - Use these instead
|
19
|
+
expect(a_type).to have_a_field(:lorem).of_type('ID')
|
20
|
+
expect(a_type).to have_a_field(:lorem).of_type('MyCustomType')
|
21
|
+
```
|
22
|
+
|
23
|
+
The reason behind this change relies on the fact that we should have a decoupling between the
|
24
|
+
internal constants used to define our API and the public names exposed through it. If we test
|
25
|
+
a published API using the internal constants, it is possible to perform breaking changes by
|
26
|
+
renaming the graphql names of our types or entities without actually breaking the tests.
|
27
|
+
|
28
|
+
If we're performing a breaking change to a public API, we want our tests to fail.
|
29
|
+
|
30
|
+
## 1.4.0 (April 16th, 2023)
|
31
|
+
|
32
|
+
- Removal of deprecated calls to #to_graphql, replacing them with #to_type_signature that was added in graphql-ruby 1.8.3 (https://github.com/khamusa/rspec-graphql_matchers/pull/43 @RobinDaugherty)
|
33
|
+
- Dropped support for legacy .define API
|
34
|
+
- Dropped support to old relay interfaces
|
35
|
+
- Fixed with_hash_key matcher for newer versions of graphql-ruby
|
36
|
+
- Fixed errors that occured in some edge cases when generating descriptions for accept_argument and have_a_field matchers
|
37
|
+
- Documentations improvement and general cleanup
|
38
|
+
- Dropped support to graphql-ruby versions before 1.10.12.
|
39
|
+
|
3
40
|
## 1.3.1 (Aug 2nd, 2021)
|
41
|
+
|
4
42
|
- Corrected gem dependencies so it properly requires RSpec when loaded (thanks to @itay-grudev)
|
5
43
|
|
6
44
|
## 1.3.0 (May 7th, 2020)
|
data/Gemfile
CHANGED
@@ -4,11 +4,3 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in rspec-graphql_matchers.gemspec
|
6
6
|
gemspec
|
7
|
-
|
8
|
-
# rubocop:disable Bundle/DuplicatedGem
|
9
|
-
if ENV['GRAPHQL_GEM_VERSION'] == '1.8'
|
10
|
-
gem 'graphql', '~> 1.8.0'
|
11
|
-
elsif ENV['GRAPHQL_GEM_VERSION'] == '1.9'
|
12
|
-
gem 'graphql', '~> 1.9.0'
|
13
|
-
end
|
14
|
-
# rubocop:enable Bundle/DuplicatedGem
|
data/README.md
CHANGED
@@ -21,16 +21,9 @@ The matchers currently supported are:
|
|
21
21
|
- `expect(a_field).to be_of_type(valid_type)`
|
22
22
|
- `expect(an_input).to accept_argument(argument_name).of_type(valid_type)`
|
23
23
|
|
24
|
-
Where a
|
24
|
+
Where `valid_type` is a your type signature as a String: `"String!"`, `"Int!"`, `"[String]!"` (note the exclamation mark at the end, as required by the [GraphQL specifications](http://graphql.org/).
|
25
25
|
|
26
|
-
|
27
|
-
- [Recommended] A String representation of a type: `"String!"`, `"Int!"`, `"[String]!"`
|
28
|
-
(note the exclamation mark at the end, as required by the [GraphQL specs](http://graphql.org/).
|
29
|
-
|
30
|
-
For objects defined with the legacy `#define` api, testing `:property`, `:hash_key` and _metadata_ is also possible by chaining `.with_property`, `.with_hash_key` and `.with_metadata`. For example:
|
31
|
-
|
32
|
-
- `expect(a_graphql_object).to have_a_field(field_name).with_property(property_name).with_metadata(metadata_hash)`
|
33
|
-
- `expect(a_graphql_object).to have_a_field(field_name).with_hash_key(hash_key)`
|
26
|
+
Please note that using references to type instances is deprecated and will be removed in a future release.
|
34
27
|
|
35
28
|
## Examples
|
36
29
|
|
@@ -41,7 +34,7 @@ class PostType < GraphQL::Schema::Object
|
|
41
34
|
graphql_name "Post"
|
42
35
|
description "A blog post"
|
43
36
|
|
44
|
-
implements GraphQL::Relay::Node
|
37
|
+
implements GraphQL::Types::Relay::Node
|
45
38
|
|
46
39
|
field :id, ID, null: false
|
47
40
|
field :comments, [String], null: false
|
@@ -49,9 +42,9 @@ class PostType < GraphQL::Schema::Object
|
|
49
42
|
field :published, Boolean, null: false, deprecation_reason: 'Use isPublished instead'
|
50
43
|
|
51
44
|
field :subposts, PostType, null: true do
|
52
|
-
argument :filter,
|
53
|
-
argument :id,
|
54
|
-
argument :isPublished,
|
45
|
+
argument :filter, String, required: false
|
46
|
+
argument :id, ID, required: false
|
47
|
+
argument :isPublished, Boolean, required: false
|
55
48
|
end
|
56
49
|
end
|
57
50
|
```
|
@@ -62,7 +55,7 @@ end
|
|
62
55
|
describe PostType do
|
63
56
|
subject { described_class }
|
64
57
|
|
65
|
-
it { is_expected.to have_field(:id).of_type(!
|
58
|
+
it { is_expected.to have_field(:id).of_type("ID!") }
|
66
59
|
it { is_expected.to have_field(:comments).of_type("[String!]!") }
|
67
60
|
it { is_expected.to have_field(:isPublished).of_type("Boolean") }
|
68
61
|
|
@@ -97,27 +90,7 @@ describe PostType do
|
|
97
90
|
end
|
98
91
|
```
|
99
92
|
|
100
|
-
### 3)
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
PostTypeWithDefineApi = GraphQL::ObjectType.define do
|
104
|
-
name "DefinedPost"
|
105
|
-
|
106
|
-
interfaces [GraphQL::Relay::Node.interface]
|
107
|
-
|
108
|
-
field :id, !types.ID, property: :post_id
|
109
|
-
field :comments, !types[types.String], hash_key: :post_comments
|
110
|
-
field :isPublished, admin_only: true
|
111
|
-
end
|
112
|
-
|
113
|
-
describe PostTypeWithDefineApi do
|
114
|
-
it { is_expected.to have_a_field(:id).of_type('ID!').with_property(:post_id) }
|
115
|
-
it { is_expected.to have_a_field(:comments).with_hash_key(:post_comments) }
|
116
|
-
it { is_expected.to have_a_field(:isPublished).with_metadata(admin_only: true) }
|
117
|
-
end
|
118
|
-
```
|
119
|
-
|
120
|
-
### 4) Test the arguments accepted by a field with `accept_argument` matcher:
|
93
|
+
### 3) Test the arguments accepted by a field with `accept_argument` matcher:
|
121
94
|
|
122
95
|
```ruby
|
123
96
|
describe PostType do
|
@@ -138,7 +111,7 @@ describe PostType do
|
|
138
111
|
end
|
139
112
|
```
|
140
113
|
|
141
|
-
###
|
114
|
+
### 4) Test an object's interface implementations:
|
142
115
|
|
143
116
|
```ruby
|
144
117
|
describe PostType do
|
@@ -148,13 +121,11 @@ describe PostType do
|
|
148
121
|
expect(subject).to implement('Node')
|
149
122
|
end
|
150
123
|
|
151
|
-
# Accepts arguments as an array and type objects directly
|
152
|
-
it { is_expected.to implement(GraphQL::Relay::Node.interface) }
|
153
124
|
it { is_expected.not_to implement('OtherInterface') }
|
154
125
|
end
|
155
126
|
```
|
156
127
|
|
157
|
-
###
|
128
|
+
### 5) Using camelize: false on field names
|
158
129
|
|
159
130
|
By default the graphql gem camelizes field names. This gem deals with it transparently:
|
160
131
|
|
@@ -162,7 +133,7 @@ By default the graphql gem camelizes field names. This gem deals with it transpa
|
|
162
133
|
class ObjectMessingWithCamelsAndSnakesType < GraphQL::Schema::Object
|
163
134
|
graphql_name 'ObjectMessingWithCamelsAndSnakes'
|
164
135
|
|
165
|
-
implements GraphQL::Relay::Node
|
136
|
+
implements GraphQL::Types::Relay::Node
|
166
137
|
|
167
138
|
field :me_gusta_los_camellos, ID, null: false
|
168
139
|
|
@@ -59,11 +59,11 @@ module RSpec
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def descriptions
|
62
|
-
|
62
|
+
results.map(&:description)
|
63
63
|
end
|
64
64
|
|
65
65
|
def failure_messages
|
66
|
-
|
66
|
+
results.map(&:failure_message)
|
67
67
|
end
|
68
68
|
|
69
69
|
def field_arguments
|
@@ -74,6 +74,10 @@ module RSpec
|
|
74
74
|
'matcher. It does not seem to be a valid GraphQL object type.'
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
def results
|
79
|
+
@results ||= []
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -17,7 +17,8 @@ module RSpec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def failure_message
|
20
|
-
"expected field '#{member_name(sample)}' to
|
20
|
+
"expected field '#{member_name(sample)}' to " \
|
21
|
+
"be of type '#{type_name(expected)}', " \
|
21
22
|
"but it was '#{type_name(sample.type)}'"
|
22
23
|
end
|
23
24
|
|
@@ -28,9 +29,9 @@ module RSpec
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def to_graphql(field_sample)
|
31
|
-
return field_sample unless field_sample.respond_to?(:
|
32
|
+
return field_sample unless field_sample.respond_to?(:to_type_signature)
|
32
33
|
|
33
|
-
field_sample.
|
34
|
+
field_sample.to_type_signature
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -80,16 +80,16 @@ module RSpec
|
|
80
80
|
field = field_collection[@expected_field_name]
|
81
81
|
field ||= field_collection[@expected_camel_field_name]
|
82
82
|
|
83
|
-
field.respond_to?(:
|
83
|
+
field.respond_to?(:to_type_signature) ? field.to_type_signature : field
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
def descriptions
|
88
|
-
|
88
|
+
results.map(&:description)
|
89
89
|
end
|
90
90
|
|
91
91
|
def failure_messages
|
92
|
-
|
92
|
+
results.map(&:failure_message)
|
93
93
|
end
|
94
94
|
|
95
95
|
def field_collection
|
@@ -103,11 +103,14 @@ module RSpec
|
|
103
103
|
|
104
104
|
def matcher_name
|
105
105
|
case @fields
|
106
|
-
when :fields
|
107
|
-
when :
|
108
|
-
when :return_fields then 'have_a_return_field'
|
106
|
+
when :fields then 'have_a_field'
|
107
|
+
when :arguments then 'have_an_input_field'
|
109
108
|
end
|
110
109
|
end
|
110
|
+
|
111
|
+
def results
|
112
|
+
@results ||= []
|
113
|
+
end
|
111
114
|
end
|
112
115
|
end
|
113
116
|
end
|
@@ -28,7 +28,11 @@ module RSpec
|
|
28
28
|
return actual_field.hash_key.to_sym if actual_field.hash_key
|
29
29
|
end
|
30
30
|
|
31
|
-
actual_field.metadata
|
31
|
+
if actual_field.respond_to?(:metadata)
|
32
|
+
return actual_field.metadata[:type_class].method_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
actual_field.method_sym
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -28,12 +28,12 @@ module RSpec
|
|
28
28
|
alias have_field have_a_field
|
29
29
|
|
30
30
|
def have_an_input_field(field_name)
|
31
|
-
RSpec::GraphqlMatchers::HaveAField.new(field_name, :
|
31
|
+
RSpec::GraphqlMatchers::HaveAField.new(field_name, :arguments)
|
32
32
|
end
|
33
33
|
alias have_input_field have_an_input_field
|
34
34
|
|
35
35
|
def have_a_return_field(field_name)
|
36
|
-
RSpec::GraphqlMatchers::HaveAField.new(field_name
|
36
|
+
RSpec::GraphqlMatchers::HaveAField.new(field_name)
|
37
37
|
end
|
38
38
|
alias have_return_field have_a_return_field
|
39
39
|
# rubocop:enable Naming/PredicateName
|
@@ -5,8 +5,20 @@ require 'graphql'
|
|
5
5
|
module RSpec
|
6
6
|
module GraphqlMatchers
|
7
7
|
module TypesHelper
|
8
|
+
class << self
|
9
|
+
extend Gem::Deprecate
|
10
|
+
|
11
|
+
GraphQL::Types.constants.each do |constant_name|
|
12
|
+
klass = GraphQL::Types.const_get(constant_name)
|
13
|
+
|
14
|
+
define_method(constant_name) { klass }
|
15
|
+
|
16
|
+
deprecate constant_name, "GraphQL::Types::#{constant_name}", 2023, 10
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
8
20
|
def types
|
9
|
-
|
21
|
+
TypesHelper
|
10
22
|
end
|
11
23
|
end
|
12
24
|
end
|
@@ -14,9 +14,6 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = 'https://github.com/khamusa/rspec-graphql_matchers'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
# raise 'RubyGems 2.0 or newer is required to protect against public gem ' \
|
18
|
-
# 'pushes.'
|
19
|
-
|
20
17
|
spec.files =
|
21
18
|
`git ls-files -z`
|
22
19
|
.split("\x0")
|
@@ -25,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
25
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
23
|
spec.require_paths = ['lib']
|
27
24
|
|
28
|
-
spec.add_dependency 'graphql', '
|
25
|
+
spec.add_dependency 'graphql', '~> 2.0'
|
29
26
|
spec.add_dependency 'rspec', '~> 3.0'
|
30
27
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
31
28
|
# CodeClimate does not yet support SimpleCov 0.18
|
metadata
CHANGED
@@ -1,33 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-graphql_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre.rc.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Brandão
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.8'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '2.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.8'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: '2.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
@@ -100,7 +94,7 @@ dependencies:
|
|
100
94
|
- - '='
|
101
95
|
- !ruby/object:Gem::Version
|
102
96
|
version: '0.71'
|
103
|
-
description:
|
97
|
+
description:
|
104
98
|
email:
|
105
99
|
- gb.samuel@gmail.com
|
106
100
|
executables: []
|
@@ -141,7 +135,7 @@ homepage: https://github.com/khamusa/rspec-graphql_matchers
|
|
141
135
|
licenses:
|
142
136
|
- MIT
|
143
137
|
metadata: {}
|
144
|
-
post_install_message:
|
138
|
+
post_install_message:
|
145
139
|
rdoc_options: []
|
146
140
|
require_paths:
|
147
141
|
- lib
|
@@ -152,12 +146,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
146
|
version: '0'
|
153
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
148
|
requirements:
|
155
|
-
- - "
|
149
|
+
- - ">"
|
156
150
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
151
|
+
version: 1.3.1
|
158
152
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
160
|
-
signing_key:
|
153
|
+
rubygems_version: 3.3.7
|
154
|
+
signing_key:
|
161
155
|
specification_version: 4
|
162
156
|
summary: Collection of rspec matchers to test your graphQL api schema.
|
163
157
|
test_files: []
|