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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +18 -7
- data/lib/rspec/graphql_matchers/implement.rb +46 -0
- data/lib/rspec/graphql_matchers/matchers.rb +5 -0
- data/lib/rspec/graphql_matchers/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb768f28fb26de27d50fa7f3cc904e59538e0f90
|
4
|
+
data.tar.gz: d1e7f770c4db3ee7dedb58635bf37be01fd50a5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b97f59f215849f232d468f982ce25395c80a24242a16a28f9efc9de451b43228dd375aa098a72e64eb97d65c3c6480576ed2dccce8fdd3ff23c644fd8aec3a3e
|
7
|
+
data.tar.gz: 12082a0895c45baae469d80a86832d5d17fa75750e3a8150d816346b7b52d85921f541a58ee564f12ae3b5f92cbda7b3da7c0db9e9c89b78a64b8ce11f7ae52b
|
data/CHANGELOG.md
CHANGED
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
|
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.
|
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-
|
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.
|
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.
|