rspec-graphql_matchers 1.2 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 277f87e873956d23acf342b90a249ca925ebba90d3ef98f14a5c7e9a7564df01
4
- data.tar.gz: 8b70cc404872f1ac41d53aa3de266f1d25e9d217bcb5dcd37384cd57249eb346
3
+ metadata.gz: 3e5dc9d71a93c8f0a762604ae835b0334ce1a7ecda6283a940a6b1a834afb81c
4
+ data.tar.gz: 2f119e9bc7d6b33c7ab1c307504a1f842dae6b6255007d6148a869569493b5f3
5
5
  SHA512:
6
- metadata.gz: a30d237270557a0b67c36bbe406c2413997cce4c673e2ba416d8b0ad48dc1b961fca3689e29eaa90c106e4a945f82bc16abfbcc4fc0de7ca145a91214611de67
7
- data.tar.gz: 37ddb46780ee142f17008757f1c86e5cfad473adbc84d888e7ed4d64965e84f20cc098af8c137aa28d2da3416fcf3dbc3b3d434d9c524006ec618577eb0cbfc2
6
+ metadata.gz: eecf40946e48ee1d4bb0cb8ae1266902c3897e8d563a772501540945ca897d4a8c9908485c6979ba3a76ffe7ece12c216ed2383c20171372f3bed4c98df66d19
7
+ data.tar.gz: f50e95f77105b2d64645a13f75b1735439176eece7991286785450a1faafa73f47c96277776ad59a5aa4c5acd16ffc85af64006c6a7e89a2029bb0dfbad74534
@@ -8,6 +8,10 @@
8
8
 
9
9
  ### Bug fixes
10
10
 
11
+ ## 1.2.1 (March 31st, 2020)
12
+
13
+ - Fixed issue causing the last release to break expectations against snake_cased fields (fixes https://github.com/khamusa/rspec-graphql_matchers/issues/30).
14
+
11
15
  ## 1.2 (Feb 6th, 2020)
12
16
 
13
17
  - Added support to underscored arguments in have_field (https://github.com/khamusa/rspec-graphql_matchers/pull/29 thanks to @makketagg)
data/README.md CHANGED
@@ -63,6 +63,10 @@ describe PostType do
63
63
  it { is_expected.to have_field(:id).of_type(!types.ID) }
64
64
  it { is_expected.to have_field(:comments).of_type("[String!]!") }
65
65
  it { is_expected.to have_field(:isPublished).of_type("Boolean") }
66
+
67
+ # The gem automatically converts field names to CamelCase, so this will
68
+ # pass even though the field was defined as field :isPublished
69
+ it { is_expected.to have_field(:is_published).of_type("Boolean") }
66
70
  end
67
71
  ```
68
72
 
@@ -138,10 +142,45 @@ describe PostType do
138
142
  end
139
143
  ```
140
144
 
145
+ ### 6) Using camelize: false on field names
146
+
147
+ By default the graphql gem camelizes field names. This gem deals with it transparently:
148
+
149
+ ```ruby
150
+ class ObjectMessingWithCamelsAndSnakesType < GraphQL::Schema::Object
151
+ graphql_name 'ObjectMessingWithCamelsAndSnakes'
152
+
153
+ implements GraphQL::Relay::Node.interface
154
+
155
+ field :me_gusta_los_camellos, ID, null: false
156
+
157
+ # note the camelize: false
158
+ field :prefiero_serpientes, ID, null: false, camelize: false
159
+ end
160
+ ```
161
+
162
+ The following specs demonstrate the current behavior of the gem regarding fields:
163
+
164
+ ```ruby
165
+ describe ObjectMessingWithCamelsAndSnakesType do
166
+ subject { described_class }
167
+
168
+ # For a field name that was automatically camelized, you can add expectations
169
+ # against both versions and we handle it transparently:
170
+ it { is_expected.to have_a_field(:meGustaLosCamellos) }
171
+ it { is_expected.to have_a_field(:me_gusta_los_camellos) }
172
+
173
+ # However, when using camelize: false, you have to use the exact case of the field definition:
174
+ it { is_expected.to have_a_field(:prefiero_serpientes) }
175
+ it { is_expected.not_to have_a_field(:prefieroSerpientes) } # Note we're using `not_to`
176
+ end
177
+ ```
178
+
179
+ This behaviour is currently active only on field name matching. PRs are welcome to
180
+ reproduce it to arguments as well.
181
+
141
182
  ## TODO
142
183
 
143
- - Support GraphQL 1.9.x;
144
- - Check the method used for resolving a field;
145
184
  - New matchers!
146
185
 
147
186
  ## Contributing
@@ -10,7 +10,10 @@ module RSpec
10
10
  module GraphqlMatchers
11
11
  class HaveAField < BaseMatcher
12
12
  def initialize(expected_field_name, fields = :fields)
13
- @expected_field_name = GraphQL::Schema::Member::BuildType.camelize(expected_field_name.to_s)
13
+ @expected_field_name = expected_field_name.to_s
14
+ @expected_camel_field_name = GraphQL::Schema::Member::BuildType.camelize(
15
+ @expected_field_name
16
+ )
14
17
  @fields = fields.to_sym
15
18
  @expectations = []
16
19
  end
@@ -18,12 +21,10 @@ module RSpec
18
21
  def matches?(graph_object)
19
22
  @graph_object = graph_object
20
23
 
21
- @actual_field = field_collection[@expected_field_name]
22
- @actual_field = @actual_field.to_graphql if @actual_field.respond_to?(:to_graphql)
23
- return false if @actual_field.nil?
24
+ return false if actual_field.nil?
24
25
 
25
26
  @results = @expectations.reject do |matcher|
26
- matcher.matches?(@actual_field)
27
+ matcher.matches?(actual_field)
27
28
  end
28
29
 
29
30
  @results.empty?
@@ -57,7 +58,7 @@ module RSpec
57
58
  base_msg = "expected #{member_name(@graph_object)} " \
58
59
  "to define field `#{@expected_field_name}`" \
59
60
 
60
- return "#{base_msg} #{failure_messages.join(', ')}" if @actual_field
61
+ return "#{base_msg} #{failure_messages.join(', ')}" if actual_field
61
62
 
62
63
  "#{base_msg} but no field was found with that name"
63
64
  end
@@ -68,6 +69,15 @@ module RSpec
68
69
 
69
70
  private
70
71
 
72
+ def actual_field
73
+ @actual_field ||= begin
74
+ field = field_collection[@expected_field_name]
75
+ field ||= field_collection[@expected_camel_field_name]
76
+
77
+ field.respond_to?(:to_graphql) ? field.to_graphql : field
78
+ end
79
+ end
80
+
71
81
  def descriptions
72
82
  @results.map(&:description)
73
83
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rspec
4
4
  module GraphqlMatchers
5
- VERSION = '1.2'
5
+ VERSION = '1.2.1'
6
6
  end
7
7
  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.2'
4
+ version: 1.2.1
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-02-06 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql