rspec-graphql_matchers 0.3.1 → 0.4.0
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 +14 -0
- data/lib/rspec/graphql_matchers/base_matcher.rb +11 -0
- data/lib/rspec/graphql_matchers/have_a_field.rb +37 -15
- data/lib/rspec/graphql_matchers/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 305fd4862eb06da7a1f37e7c55b6f9af96eca4e2
|
4
|
+
data.tar.gz: 343daa1c81d534979ee724ed6f5206765fa4109c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eaaa0082cadbd26d2e9a577c0ed364ad769f5cfffd7fd8cb54784ad9684b2b9e44e0833e9d4fe25a4a6a22ba4a7c9da3298b329fad40a211dca0ce676885da4
|
7
|
+
data.tar.gz: 7ab8f2831ebf8f6dbe80acbd889b6e92ae919b092bf6f796749909ce47cd62542808c5979ab970cc425fbc88374c40045c3d911e102929cce1405b6645628c88
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,20 @@
|
|
8
8
|
|
9
9
|
### Bug fixes
|
10
10
|
|
11
|
+
## 0.4.0 (Feb 10, 2017)
|
12
|
+
|
13
|
+
### Breaking changes
|
14
|
+
|
15
|
+
### Deprecations
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
- Improved error messages for `have_a_field...of_type`
|
20
|
+
|
21
|
+
### Bug fixes
|
22
|
+
|
23
|
+
- FIXEd Type check when using the form `have_a_field(field_name).of_type(types.X)` not working. It was working if the expected type was provided as a String, but not when using the GraphQL constants.
|
24
|
+
|
11
25
|
## 0.3.0 (Sep 16, 2016)
|
12
26
|
|
13
27
|
### Breaking changes
|
@@ -1,20 +1,27 @@
|
|
1
|
+
require_relative 'base_matcher'
|
2
|
+
|
1
3
|
module RSpec
|
2
4
|
module GraphqlMatchers
|
3
|
-
class HaveAField
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@
|
5
|
+
class HaveAField < BaseMatcher
|
6
|
+
def initialize(expected_field_name)
|
7
|
+
@expected_field_name = expected_field_name.to_s
|
8
|
+
@expected_field_type = @graph_object = nil
|
7
9
|
end
|
8
10
|
|
9
11
|
def matches?(graph_object)
|
10
12
|
@graph_object = graph_object
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
unless @graph_object.respond_to?(:fields)
|
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]
|
20
|
+
valid_field? && types_match?(@actual_field.type, @expected_field_type)
|
14
21
|
end
|
15
22
|
|
16
|
-
def that_returns(
|
17
|
-
@
|
23
|
+
def that_returns(expected_field_type)
|
24
|
+
@expected_field_type = expected_field_type
|
18
25
|
|
19
26
|
self
|
20
27
|
end
|
@@ -22,23 +29,38 @@ module RSpec
|
|
22
29
|
alias of_type that_returns
|
23
30
|
|
24
31
|
def failure_message
|
25
|
-
"expected #{describe_obj(@graph_object)} to
|
32
|
+
"expected #{describe_obj(@graph_object)} to " \
|
33
|
+
"#{description}, #{explanation}."
|
26
34
|
end
|
27
35
|
|
28
36
|
def description
|
29
|
-
"define field `#{@
|
37
|
+
"define field `#{@expected_field_name}`" + of_type_description
|
30
38
|
end
|
31
39
|
|
32
40
|
private
|
33
41
|
|
34
|
-
def
|
35
|
-
return '' unless @
|
42
|
+
def explanation
|
43
|
+
return 'but no field was found with that name' unless @actual_field
|
44
|
+
|
45
|
+
"but the field type was `#{@actual_field.type}`"
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid_field?
|
49
|
+
unless @expected_field_type.nil? || @actual_field.respond_to?(:type)
|
50
|
+
error_msg = "The `#{@expected_field_name}` field defined by the GraphQL " \
|
51
|
+
'object does\'t seem valid as it does not respond to #type. ' \
|
52
|
+
"\n\n\tThe field found was #{@actual_field.inspect}. "
|
53
|
+
puts error_msg
|
54
|
+
raise error_msg
|
55
|
+
end
|
36
56
|
|
37
|
-
|
57
|
+
@actual_field
|
38
58
|
end
|
39
59
|
|
40
|
-
def
|
41
|
-
|
60
|
+
def of_type_description
|
61
|
+
return '' unless @expected_field_type
|
62
|
+
|
63
|
+
" of type `#{@expected_field_type}`"
|
42
64
|
end
|
43
65
|
|
44
66
|
def describe_obj(field)
|
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.4.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: 2017-
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- bin/setup
|
110
110
|
- lib/rspec/graphql_matchers.rb
|
111
111
|
- lib/rspec/graphql_matchers/accept_arguments.rb
|
112
|
+
- lib/rspec/graphql_matchers/base_matcher.rb
|
112
113
|
- lib/rspec/graphql_matchers/be_of_type.rb
|
113
114
|
- lib/rspec/graphql_matchers/have_a_field.rb
|
114
115
|
- lib/rspec/graphql_matchers/matchers.rb
|