rspec-graphql_matchers 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -6
- data/README.md +12 -0
- data/lib/rspec/graphql_matchers/accept_argument.rb +4 -0
- data/lib/rspec/graphql_matchers/accept_arguments.rb +2 -0
- data/lib/rspec/graphql_matchers/have_a_field.rb +6 -0
- data/lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb +36 -0
- data/lib/rspec/graphql_matchers/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b3cd22e67266948bf838945b0330bf050d19c44a4e336cfcd2fec2ad629350f
|
4
|
+
data.tar.gz: 14637372879e218e39922e323614d47426a93370425ed083b94dbec8ed597340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bc45acd938927b143eb669e042f5ebcd6758be29602761d31b3101e77d722a66cbc896459f326fa9a44779bd1f6139c0e23b9a0f3d6e31418d6feb90526e58c
|
7
|
+
data.tar.gz: e011517e436af44e654b31847d561c2f588a5a12315d06235dbd2ad0d12770a7281e242d73c13772565c0885dc05ecd0fc7bdb19824365a3c7583c6c5dd74522
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
### Deprecations
|
3
|
+
## 1.3.0 (May 7th, 2020)
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
### Bug fixes
|
5
|
+
- `accept_argument` matcher accepts underscored argument names and passes even if the actual argument is camel-cased (https://github.com/khamusa/rspec-graphql_matchers/pull/32 thanks to @TonyArra);
|
6
|
+
- `have_a_field` matcher accepts `.with_deprecation_reason` (https://github.com/khamusa/rspec-graphql_matchers/pull/34 thanks to @TonyArra).
|
10
7
|
|
11
8
|
## 1.2.1 (March 31st, 2020)
|
12
9
|
|
data/README.md
CHANGED
@@ -46,10 +46,12 @@ class PostType < GraphQL::Schema::Object
|
|
46
46
|
field :id, ID, null: false
|
47
47
|
field :comments, [String], null: false
|
48
48
|
field :isPublished, Boolean, null: true
|
49
|
+
field :published, Boolean, null: false, deprecation_reason: 'Use isPublished instead'
|
49
50
|
|
50
51
|
field :subposts, PostType, null: true do
|
51
52
|
argument :filter, types.String, required: false
|
52
53
|
argument :id, types.ID, required: false
|
54
|
+
argument :isPublished, types.Boolean, required: false
|
53
55
|
end
|
54
56
|
end
|
55
57
|
```
|
@@ -64,6 +66,12 @@ describe PostType do
|
|
64
66
|
it { is_expected.to have_field(:comments).of_type("[String!]!") }
|
65
67
|
it { is_expected.to have_field(:isPublished).of_type("Boolean") }
|
66
68
|
|
69
|
+
# Check a field is deprecated
|
70
|
+
it { is_expected.to have_field(:published).with_deprecation_reason }
|
71
|
+
it { is_expected.to have_field(:published).with_deprecation_reason('Use isPublished instead') }
|
72
|
+
it { is_expected.not_to have_field(:published).with_deprecation_reason('Wrong reason') }
|
73
|
+
it { is_expected.not_to have_field(:isPublished).with_deprecation_reason }
|
74
|
+
|
67
75
|
# The gem automatically converts field names to CamelCase, so this will
|
68
76
|
# pass even though the field was defined as field :isPublished
|
69
77
|
it { is_expected.to have_field(:is_published).of_type("Boolean") }
|
@@ -122,6 +130,10 @@ describe PostType do
|
|
122
130
|
end
|
123
131
|
|
124
132
|
it { is_expected.not_to accept_argument(:weirdo) }
|
133
|
+
|
134
|
+
# The gem automatically converts argument names to CamelCase, so this will
|
135
|
+
# pass even though the argument was defined as :isPublished
|
136
|
+
it { is_expected.to accept_argument(:is_published).of_type("Boolean") }
|
125
137
|
end
|
126
138
|
end
|
127
139
|
```
|
@@ -17,12 +17,16 @@ module RSpec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
@expected_arg_name = expected_arg_name.to_s
|
20
|
+
@expected_camel_arg_name = GraphQL::Schema::Member::BuildType.camelize(
|
21
|
+
@expected_arg_name
|
22
|
+
)
|
20
23
|
end
|
21
24
|
|
22
25
|
def matches?(graph_object)
|
23
26
|
@graph_object = graph_object
|
24
27
|
|
25
28
|
@actual_argument = field_arguments[@expected_arg_name]
|
29
|
+
@actual_argument ||= field_arguments[@expected_camel_arg_name]
|
26
30
|
return false if @actual_argument.nil?
|
27
31
|
|
28
32
|
@results = @expectations.select do |matcher|
|
@@ -29,7 +29,9 @@ module RSpec
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def matches_argument?(arg_name, arg_type)
|
32
|
+
camel_arg_name = GraphQL::Schema::Member::BuildType.camelize(arg_name.to_s)
|
32
33
|
actual_arg = actual_field.arguments[arg_name.to_s]
|
34
|
+
actual_arg ||= actual_field.arguments[camel_arg_name]
|
33
35
|
|
34
36
|
actual_arg && types_match?(actual_arg.type, arg_type)
|
35
37
|
end
|
@@ -5,6 +5,7 @@ require_relative './have_a_field_matchers/of_type'
|
|
5
5
|
require_relative './have_a_field_matchers/with_property'
|
6
6
|
require_relative './have_a_field_matchers/with_metadata'
|
7
7
|
require_relative './have_a_field_matchers/with_hash_key'
|
8
|
+
require_relative './have_a_field_matchers/with_deprecation_reason'
|
8
9
|
|
9
10
|
module RSpec
|
10
11
|
module GraphqlMatchers
|
@@ -54,6 +55,11 @@ module RSpec
|
|
54
55
|
self
|
55
56
|
end
|
56
57
|
|
58
|
+
def with_deprecation_reason(expected_reason = nil)
|
59
|
+
@expectations << HaveAFieldMatchers::WithDeprecationReason.new(expected_reason)
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
57
63
|
def failure_message
|
58
64
|
base_msg = "expected #{member_name(@graph_object)} " \
|
59
65
|
"to define field `#{@expected_field_name}`" \
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module GraphqlMatchers
|
5
|
+
module HaveAFieldMatchers
|
6
|
+
class WithDeprecationReason
|
7
|
+
def initialize(expected_reason)
|
8
|
+
@expected_reason = expected_reason
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(actual_field)
|
12
|
+
@actual_reason = actual_field.deprecation_reason
|
13
|
+
|
14
|
+
if @expected_reason.nil?
|
15
|
+
!actual_field.deprecation_reason.nil?
|
16
|
+
else
|
17
|
+
actual_field.deprecation_reason == @expected_reason
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message
|
22
|
+
message = "#{description}, but it was "
|
23
|
+
message + (@actual_reason.nil? ? 'not deprecated' : "`#{@actual_reason}`")
|
24
|
+
end
|
25
|
+
|
26
|
+
def description
|
27
|
+
if @expected_reason.nil?
|
28
|
+
'with a deprecation reason'
|
29
|
+
else
|
30
|
+
"with deprecation reason `#{@expected_reason}`"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-graphql_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Brandão
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/rspec/graphql_matchers/be_of_type.rb
|
115
115
|
- lib/rspec/graphql_matchers/have_a_field.rb
|
116
116
|
- lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb
|
117
|
+
- lib/rspec/graphql_matchers/have_a_field_matchers/with_deprecation_reason.rb
|
117
118
|
- lib/rspec/graphql_matchers/have_a_field_matchers/with_hash_key.rb
|
118
119
|
- lib/rspec/graphql_matchers/have_a_field_matchers/with_metadata.rb
|
119
120
|
- lib/rspec/graphql_matchers/have_a_field_matchers/with_property.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.7.
|
146
|
+
rubygems_version: 2.7.10
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Collection of rspec matchers to test your graphQL api schema.
|