rspec-graphql_matchers 0.4.0 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -5
- data/README.md +6 -5
- data/lib/rspec/graphql_matchers/have_a_field.rb +20 -7
- data/lib/rspec/graphql_matchers/matchers.rb +12 -0
- data/lib/rspec/graphql_matchers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef64269a3e7859791ef772fa3fa7e5c1971c23b0
|
4
|
+
data.tar.gz: 383ed8c0d083b7dafc086179c5266ddc37d2b2c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a9c8803fbfe709451399b1a220ffcc2918525e595760b1d2c89f156066dd47dd75ce0a9bfe2520f4e5fb6944733d2e2bcca4082513a1f1bc24196eafffd679
|
7
|
+
data.tar.gz: 6e73cc8a63366f37bd445cc7cbd0d0af44b5a40565d907fc97164e03e298fa01d54dcdb4e0109b47603096a803709a7e290c0843188639d73891f801b7fb38fb
|
data/CHANGELOG.md
CHANGED
@@ -8,19 +8,21 @@
|
|
8
8
|
|
9
9
|
### Bug fixes
|
10
10
|
|
11
|
-
## 0.
|
11
|
+
## 0.5.0 (May 10, 2017)
|
12
12
|
|
13
|
-
###
|
13
|
+
### New features
|
14
14
|
|
15
|
-
|
15
|
+
- (PR #4) New matchers for mutations: `have_an_input_field` and `have_a_return_field` (Thanks to @aaronklaassen).
|
16
|
+
|
17
|
+
## 0.4.0 (Feb, 2017)
|
16
18
|
|
17
19
|
### New features
|
18
20
|
|
19
|
-
-
|
21
|
+
- Improvements on error messages of have_a_field(...).of_type(...)
|
20
22
|
|
21
23
|
### Bug fixes
|
22
24
|
|
23
|
-
-
|
25
|
+
- Fixed a bug preventing proper type checking when using matchers in the form have_a_field(fname).of_type(types.X). The bug would not happen when providing the type expectation as a string, only when using the GraphQL constants.
|
24
26
|
|
25
27
|
## 0.3.0 (Sep 16, 2016)
|
26
28
|
|
data/README.md
CHANGED
@@ -11,9 +11,12 @@ gem 'rspec-graphql_matchers'
|
|
11
11
|
## Usage
|
12
12
|
|
13
13
|
The matchers currently supported are:
|
14
|
-
- `expect(
|
15
|
-
- `expect(
|
16
|
-
- `expect(
|
14
|
+
- `expect(a_graphql_object).to have_a_field(field_name).that_returns(valid_type)`
|
15
|
+
- `expect(a_mutation_type).to have_a_return_field(field_name).returning(valid_type)`
|
16
|
+
- `expect(a_mutation_type).to have_an_input_field(field_name).of_type(valid_type)`
|
17
|
+
- `expect(a_field).to be_of_type(valid_type)`
|
18
|
+
- `expect(an_input).to accept_arguments(hash_of_arg_names_and_valid_types)`
|
19
|
+
- `expect(an_input).to accept_arguments(hash_of_arg_names_and_valid_types)`
|
17
20
|
|
18
21
|
Where a valid type for the expectation is either:
|
19
22
|
- A `GraphQL::ObjectType` object (ex: `types.String`, `!types.Int`, `types[types.Int]`, or your own)
|
@@ -137,8 +140,6 @@ For better fluency, `accept_arguments` is also available in singular form, as
|
|
137
140
|
|
138
141
|
## TODO
|
139
142
|
|
140
|
-
- Setup CI and integrate w/codeclimate
|
141
|
-
- Setup codeclimate / CI badges
|
142
143
|
- New matchers!
|
143
144
|
|
144
145
|
## Contributing
|
@@ -3,20 +3,16 @@ require_relative 'base_matcher'
|
|
3
3
|
module RSpec
|
4
4
|
module GraphqlMatchers
|
5
5
|
class HaveAField < BaseMatcher
|
6
|
-
def initialize(expected_field_name)
|
6
|
+
def initialize(expected_field_name, fields = :fields)
|
7
7
|
@expected_field_name = expected_field_name.to_s
|
8
8
|
@expected_field_type = @graph_object = nil
|
9
|
+
@fields = fields.to_sym
|
9
10
|
end
|
10
11
|
|
11
12
|
def matches?(graph_object)
|
12
13
|
@graph_object = graph_object
|
13
14
|
|
14
|
-
|
15
|
-
raise "Invalid object #{@graph_object} provided to have_a_field " \
|
16
|
-
'matcher. It does not seem to be a valid GraphQL object type.'
|
17
|
-
end
|
18
|
-
|
19
|
-
@actual_field = @graph_object.fields[@expected_field_name]
|
15
|
+
@actual_field = field_collection[@expected_field_name]
|
20
16
|
valid_field? && types_match?(@actual_field.type, @expected_field_type)
|
21
17
|
end
|
22
18
|
|
@@ -66,6 +62,23 @@ module RSpec
|
|
66
62
|
def describe_obj(field)
|
67
63
|
field.respond_to?(:name) && field.name || field.inspect
|
68
64
|
end
|
65
|
+
|
66
|
+
def field_collection
|
67
|
+
if @graph_object.respond_to?(@fields)
|
68
|
+
@graph_object.public_send(@fields)
|
69
|
+
else
|
70
|
+
raise "Invalid object #{@graph_object} provided to #{matcher_name} " \
|
71
|
+
'matcher. It does not seem to be a valid GraphQL object type.'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def matcher_name
|
76
|
+
case @fields
|
77
|
+
when :fields then 'have_a_field'
|
78
|
+
when :input_fields then 'have_an_input_field'
|
79
|
+
when :return_fields then 'have_a_return_field'
|
80
|
+
end
|
81
|
+
end
|
69
82
|
end
|
70
83
|
end
|
71
84
|
end
|
@@ -19,5 +19,17 @@ module RSpec
|
|
19
19
|
RSpec::GraphqlMatchers::HaveAField.new(field_name)
|
20
20
|
end
|
21
21
|
alias have_field have_a_field
|
22
|
+
|
23
|
+
# rubocop:disable Style/PredicateName
|
24
|
+
def have_an_input_field(field_name)
|
25
|
+
RSpec::GraphqlMatchers::HaveAField.new(field_name, :input_fields)
|
26
|
+
end
|
27
|
+
alias have_input_field have_an_input_field
|
28
|
+
|
29
|
+
# rubocop:disable Style/PredicateName
|
30
|
+
def have_a_return_field(field_name)
|
31
|
+
RSpec::GraphqlMatchers::HaveAField.new(field_name, :return_fields)
|
32
|
+
end
|
33
|
+
alias have_return_field have_a_return_field
|
22
34
|
end
|
23
35
|
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.5'
|
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-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.6.8
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Collection of rspec matchers to test your graphQL api schema.
|