rspec-graphql_matchers 0.5 → 0.6

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
  SHA1:
3
- metadata.gz: ef64269a3e7859791ef772fa3fa7e5c1971c23b0
4
- data.tar.gz: 383ed8c0d083b7dafc086179c5266ddc37d2b2c4
3
+ metadata.gz: cb768f28fb26de27d50fa7f3cc904e59538e0f90
4
+ data.tar.gz: d1e7f770c4db3ee7dedb58635bf37be01fd50a5a
5
5
  SHA512:
6
- metadata.gz: b3a9c8803fbfe709451399b1a220ffcc2918525e595760b1d2c89f156066dd47dd75ce0a9bfe2520f4e5fb6944733d2e2bcca4082513a1f1bc24196eafffd679
7
- data.tar.gz: 6e73cc8a63366f37bd445cc7cbd0d0af44b5a40565d907fc97164e03e298fa01d54dcdb4e0109b47603096a803709a7e290c0843188639d73891f801b7fb38fb
6
+ metadata.gz: b97f59f215849f232d468f982ce25395c80a24242a16a28f9efc9de451b43228dd375aa098a72e64eb97d65c3c6480576ed2dccce8fdd3ff23c644fd8aec3a3e
7
+ data.tar.gz: 12082a0895c45baae469d80a86832d5d17fa75750e3a8150d816346b7b52d85921f541a58ee564f12ae3b5f92cbda7b3da7c0db9e9c89b78a64b8ce11f7ae52b
@@ -8,6 +8,12 @@
8
8
 
9
9
  ### Bug fixes
10
10
 
11
+ ## 0.6.0 (July 25, 2017)
12
+
13
+ ### New features
14
+
15
+ - (PR #6) New matchers for interfaces: `expect(...).to implement(interface)` (Thanks to @marcgreenstock).
16
+
11
17
  ## 0.5.0 (May 10, 2017)
12
18
 
13
19
  ### New features
data/README.md CHANGED
@@ -12,6 +12,7 @@ gem 'rspec-graphql_matchers'
12
12
 
13
13
  The matchers currently supported are:
14
14
  - `expect(a_graphql_object).to have_a_field(field_name).that_returns(valid_type)`
15
+ - `expect(a_graphql_object).to interface(interface_name, ...)`
15
16
  - `expect(a_mutation_type).to have_a_return_field(field_name).returning(valid_type)`
16
17
  - `expect(a_mutation_type).to have_an_input_field(field_name).of_type(valid_type)`
17
18
  - `expect(a_field).to be_of_type(valid_type)`
@@ -33,6 +34,8 @@ PostType = GraphQL::ObjectType.define do
33
34
  name "Post"
34
35
  description "A blog post"
35
36
 
37
+ interfaces [GraphQL::Relay::Node.interface]
38
+
36
39
  field :id, !types.ID
37
40
 
38
41
  field :comments, !types[types.String]
@@ -106,11 +109,6 @@ describe PostType do
106
109
  end
107
110
  ```
108
111
 
109
- Having to define `types` everywhere is quite annoying. If you prefer, you can
110
- just `include RSpec::GraphqlMatchers::TypesHelper` once
111
- (for example in your `spec_helper.rb`)
112
- and the `types` shortcut will be available within the include context.
113
-
114
112
  ### 3) Test the arguments accepted by a field with `accept_arguments` matcher:
115
113
 
116
114
  ```ruby
@@ -132,6 +130,20 @@ describe PostType do
132
130
  end
133
131
  ```
134
132
 
133
+ ### 4) Test an object's interface implementations:
134
+
135
+ ```ruby
136
+ describe PostType do
137
+ it 'interfaces Node' do
138
+ expect(subject).to implement('Node')
139
+ end
140
+
141
+ # Accepts arguments as an array and type objects directly
142
+ it { is_expected.to implement(GraphQL::Relay::Node.interface) }
143
+ it { is_expected.not_to implement('OtherInterface') }
144
+ end
145
+ ```
146
+
135
147
  The spec will only pass if all attributes/types specified in the hash are
136
148
  defined on the field.
137
149
 
@@ -156,6 +168,5 @@ contributors are expected to adhere to the
156
168
 
157
169
  ## License
158
170
 
159
- The gem is available as open source under the terms of the
171
+ The gem is available as open source under the terms of the
160
172
  [MIT License](http://opensource.org/licenses/MIT).
161
-
@@ -0,0 +1,46 @@
1
+ require_relative 'base_matcher'
2
+
3
+ module RSpec
4
+ module GraphqlMatchers
5
+ class Implement < BaseMatcher
6
+ def initialize(interface_names)
7
+ @expected = interface_names.map(&:to_s)
8
+ end
9
+
10
+ def matches?(graph_object)
11
+ @graph_object = graph_object
12
+ @actual = actual
13
+ @expected.each do |name|
14
+ return false unless @actual.include?(name)
15
+ end
16
+ end
17
+
18
+ def failure_message
19
+ message = "expected interfaces: #{@expected.join(', ')}\n"
20
+ message += "actual interfaces: #{@actual.join(', ')}"
21
+ message
22
+ end
23
+
24
+ def failure_message_when_negated
25
+ message = "unexpected interfaces: #{@expected.join(', ')}\n"
26
+ message += "actual interfaces: #{@actual.join(', ')}"
27
+ message
28
+ end
29
+
30
+ def description
31
+ "implement #{@expected.join(', ')}"
32
+ end
33
+
34
+ private
35
+
36
+ def actual
37
+ if @graph_object.respond_to?(:interfaces)
38
+ @graph_object.interfaces.map(&:to_s)
39
+ else
40
+ raise "Invalid object #{@graph_object} provided to #{matcher_name} " \
41
+ 'matcher. It does not seem to be a valid GraphQL object type.'
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -2,6 +2,7 @@ require 'rspec/matchers'
2
2
  require 'rspec/graphql_matchers/be_of_type'
3
3
  require 'rspec/graphql_matchers/accept_arguments'
4
4
  require 'rspec/graphql_matchers/have_a_field'
5
+ require 'rspec/graphql_matchers/implement'
5
6
 
6
7
  module RSpec
7
8
  module Matchers
@@ -31,5 +32,9 @@ module RSpec
31
32
  RSpec::GraphqlMatchers::HaveAField.new(field_name, :return_fields)
32
33
  end
33
34
  alias have_return_field have_a_return_field
35
+
36
+ def implement(*interface_names)
37
+ RSpec::GraphqlMatchers::Implement.new(interface_names.flatten)
38
+ end
34
39
  end
35
40
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module GraphqlMatchers
3
- VERSION = '0.5'.freeze
3
+ VERSION = '0.6'.freeze
4
4
  end
5
5
  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: '0.5'
4
+ version: '0.6'
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: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -112,6 +112,7 @@ files:
112
112
  - lib/rspec/graphql_matchers/base_matcher.rb
113
113
  - lib/rspec/graphql_matchers/be_of_type.rb
114
114
  - lib/rspec/graphql_matchers/have_a_field.rb
115
+ - lib/rspec/graphql_matchers/implement.rb
115
116
  - lib/rspec/graphql_matchers/matchers.rb
116
117
  - lib/rspec/graphql_matchers/types_helper.rb
117
118
  - lib/rspec/graphql_matchers/version.rb
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.6.8
140
+ rubygems_version: 2.6.12
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Collection of rspec matchers to test your graphQL api schema.