rspec-graphql_response 0.1.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +14 -0
- data/.gitignore +3 -0
- data/.gituprc +128 -0
- data/Gemfile.lock +16 -7
- data/README.md +64 -72
- data/RELEASE_NOTES.md +45 -0
- data/UPGRADE.md +41 -0
- data/docs/add_helper.md +94 -0
- data/docs/add_validator.md +168 -1
- data/docs/configuration.md +12 -0
- data/docs/execute_graphql.md +50 -0
- data/docs/graphql_spec_type.md +14 -0
- data/docs/have_operation.md +46 -0
- data/docs/operation.md +1 -36
- data/docs/response.md +1 -0
- data/docs/response_data.md +146 -0
- data/lib/rspec/graphql_response.rb +2 -1
- data/lib/rspec/graphql_response/dig_dug/dig_dug.rb +83 -0
- data/lib/rspec/graphql_response/helpers.rb +35 -7
- data/lib/rspec/graphql_response/helpers/execute_graphql.rb +14 -1
- data/lib/rspec/graphql_response/helpers/graphql_context.rb +3 -0
- data/lib/rspec/graphql_response/helpers/graphql_operation.rb +3 -0
- data/lib/rspec/graphql_response/helpers/graphql_variables.rb +3 -0
- data/lib/rspec/graphql_response/helpers/operation.rb +1 -0
- data/lib/rspec/graphql_response/helpers/response_data.rb +13 -0
- data/lib/rspec/graphql_response/matchers.rb +1 -0
- data/lib/rspec/graphql_response/matchers/have_errors.rb +2 -2
- data/lib/rspec/graphql_response/matchers/have_operation.rb +23 -0
- data/lib/rspec/graphql_response/validators.rb +6 -0
- data/lib/rspec/graphql_response/validators/have_operation.rb +24 -0
- data/lib/rspec/graphql_response/version.rb +1 -1
- data/rspec-graphql_response.gemspec +3 -2
- metadata +52 -21
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 647c52ffa5ae347bc9c2166bd94af15ee82556d10f37fa5a11a0cf0229d40b31
|
4
|
+
data.tar.gz: a93873e4d4a40a9a4702026321d96d913056188dd51eec86836232add5e7c4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad72db1bdd814a65f02cf4ee9a59c9836c452003fe840e9c28903aa805ab0553fcd7afa4558d610c63c5ae1959fea61690f037641bd3fa31b417c378ed1805a
|
7
|
+
data.tar.gz: 46ec7e724d5784feb01e33fbb5024d9c8713ddb8df77a1efb2273f1dd94c2bf8c3658ecb1f11ad9065741119b6e4a71815f9911ba3e87a779caafe97563b2dd8
|
@@ -0,0 +1,14 @@
|
|
1
|
+
name: Test rspec-graphql_response
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ $default-branch ]
|
5
|
+
pull_request:
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
bundler-cache: true
|
14
|
+
- run: bin/rspec
|
data/.gitignore
CHANGED
data/.gituprc
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Gitup: Git Update Dance Configuration
|
2
|
+
# -------------------------------------
|
3
|
+
# configuration for gitup can be set as a default for the current user
|
4
|
+
# by adding a ~/.gituprc file with settings
|
5
|
+
#
|
6
|
+
# current project or local directory settings can be added in ./.gituprc
|
7
|
+
#
|
8
|
+
# the .gituprc file is a valid shell script, loaded every time gitup is
|
9
|
+
# run. this means you can add logic, functions, and other calls to the
|
10
|
+
# .gituprc file and it will be executed at runtime
|
11
|
+
|
12
|
+
|
13
|
+
# GIT CONFIGURATION
|
14
|
+
# -----------------
|
15
|
+
# Manages the git branch update process for your project
|
16
|
+
#
|
17
|
+
# GITUP_SKIP_UPDATE:
|
18
|
+
# Whether or not a git update is performed prior to running
|
19
|
+
# the bundle install or db:migrate steps
|
20
|
+
#
|
21
|
+
# Options:
|
22
|
+
# 0: (default) do not skip the update
|
23
|
+
# 1: skip the update
|
24
|
+
#
|
25
|
+
# GITUP_MERGE_COMMAND:
|
26
|
+
# How to update the local git branch, from the upstream branch.
|
27
|
+
#
|
28
|
+
# Options:
|
29
|
+
# rebase: (default) force a rebase of the upstream branch
|
30
|
+
# merge: force a merge of the upstream branch
|
31
|
+
# <other>: your own command: `git <other> <remote>/<branch>`
|
32
|
+
#
|
33
|
+
# GITUP_REMOTE_NAME:
|
34
|
+
# The git remote name to pull from
|
35
|
+
#
|
36
|
+
# Default:
|
37
|
+
# origin
|
38
|
+
#
|
39
|
+
# GITUP_BRANCH_NAME:
|
40
|
+
# The main remote branch name to pull, from which your current
|
41
|
+
# branch will be updated
|
42
|
+
#
|
43
|
+
# Default:
|
44
|
+
# development
|
45
|
+
#
|
46
|
+
# GITUP_GIT_UPDATE_FN:
|
47
|
+
# The method called to update your git branch. Responsible
|
48
|
+
# for handling git pull, git merge or rebase, etc.
|
49
|
+
#
|
50
|
+
# Params:
|
51
|
+
# $1: Merge Command
|
52
|
+
# $2: Remote Name
|
53
|
+
# $3: Branch Name
|
54
|
+
#
|
55
|
+
# Default:
|
56
|
+
# GITUP_GIT_UPDATE_FN=__gitup_git_update
|
57
|
+
#
|
58
|
+
GITUP_SKIP_UPDATE=0
|
59
|
+
# GITUP_MERGE_COMMAND=rebase
|
60
|
+
GITUP_REMOTE_NAME=origin
|
61
|
+
GITUP_BRANCH_NAME=main
|
62
|
+
GITUP_GIT_UPDATE_FN=__gitup_git_update
|
63
|
+
|
64
|
+
# ADVANCED GIT CONFIGURATION
|
65
|
+
# --------------------------
|
66
|
+
# This .gituprs file is a full bash script. You can add logic
|
67
|
+
# to determine how to update, based on your current branch, etc.
|
68
|
+
#
|
69
|
+
# Examples:
|
70
|
+
#
|
71
|
+
# How to change merge command for specific branches
|
72
|
+
#
|
73
|
+
# current git branch
|
74
|
+
local branch_name=$(git symbolic-ref -q HEAD)
|
75
|
+
|
76
|
+
# remove the `refs/heads/` structure from the name
|
77
|
+
branch_name=${branch_name##refs/heads/}
|
78
|
+
|
79
|
+
# merge if we're in 'development' branch
|
80
|
+
if [[ $branch_name == $GITUP_BRANCH_NAME ]]; then
|
81
|
+
GITUP_MERGE_COMMAND=merge
|
82
|
+
else
|
83
|
+
GITUP_MERGE_COMMAND=rebase
|
84
|
+
fi
|
85
|
+
|
86
|
+
# DEPENDENCY INSTALLATION
|
87
|
+
# -----------------------
|
88
|
+
# Manage the step installs dependencies, after updating git.
|
89
|
+
# For example, run `bundle install` (default) and/or other
|
90
|
+
# commands to keep your project's dependencies up to date.
|
91
|
+
#
|
92
|
+
# GITUP_SKIP_INSTALL_DEPENDENCIES:
|
93
|
+
# Whether or not to skip the step that runs immediately after
|
94
|
+
# the git-update completes
|
95
|
+
#
|
96
|
+
# Options:
|
97
|
+
# 0: (default) do not skip the after_update step
|
98
|
+
# 1: skip the after_update step
|
99
|
+
#
|
100
|
+
# GITUP_INSTALL_DEPENDENCIES_FN:
|
101
|
+
# Function to run after gitup has completed the git update process
|
102
|
+
#
|
103
|
+
# Default:
|
104
|
+
# GITUP_INSTALL_DEPENDENCIES_FN=__gitup_install_dependencies
|
105
|
+
#
|
106
|
+
GITUP_SKIP_INSTALL_DEPENDENCIES=0
|
107
|
+
GITUP_INSTALL_DEPENDENCIES_FN=__gitup_install_dependencies
|
108
|
+
|
109
|
+
# RUN MIGRATIONS
|
110
|
+
# --------------
|
111
|
+
# Manage the process of running schema and/or data migrations,
|
112
|
+
# after your project's post-git-update function has run
|
113
|
+
#
|
114
|
+
# GITUP_SKIP_MIGRATIONS:
|
115
|
+
# Whether or not to skip the db:migration steps after the git update
|
116
|
+
#
|
117
|
+
# Options:
|
118
|
+
# 0: (default) do not skip the db:migration steps
|
119
|
+
# 1: skip the db:migration steps
|
120
|
+
#
|
121
|
+
# GITUP_RUN_MIGRATIONS_FN:
|
122
|
+
# Function to run migrations. Occurs after git update and post-update steps
|
123
|
+
#
|
124
|
+
# Default:
|
125
|
+
# GITUP_RUN_MIGRATIONS_FN=__gitup_migrations
|
126
|
+
#
|
127
|
+
GITUP_SKIP_MIGRATIONS=1
|
128
|
+
# GITUP_RUN_MIGRATIONS_FN=__gitup_migrations
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-graphql_response (0.1
|
5
|
-
|
4
|
+
rspec-graphql_response (0.4.1)
|
5
|
+
graphql (>= 1.0)
|
6
|
+
rspec (>= 3.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
attr_extras (6.2.4)
|
10
12
|
byebug (11.1.3)
|
11
13
|
coderay (1.1.3)
|
12
14
|
diff-lcs (1.4.4)
|
13
|
-
graphql (1.12.
|
15
|
+
graphql (1.12.6)
|
14
16
|
method_source (1.0.0)
|
17
|
+
optimist (3.0.1)
|
18
|
+
patience_diff (1.2.0)
|
19
|
+
optimist (~> 3.0)
|
15
20
|
pry (0.14.0)
|
16
21
|
coderay (~> 1.1)
|
17
22
|
method_source (~> 1.0)
|
@@ -32,17 +37,21 @@ GEM
|
|
32
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
38
|
rspec-support (~> 3.10.0)
|
34
39
|
rspec-support (3.10.2)
|
40
|
+
super_diff (0.6.1)
|
41
|
+
attr_extras (>= 6.2.4)
|
42
|
+
diff-lcs
|
43
|
+
patience_diff
|
35
44
|
|
36
45
|
PLATFORMS
|
37
46
|
ruby
|
38
47
|
|
39
48
|
DEPENDENCIES
|
40
49
|
bundler (~> 1.17)
|
41
|
-
|
42
|
-
pry
|
43
|
-
|
44
|
-
rake
|
50
|
+
pry (~> 0.14)
|
51
|
+
pry-byebug (~> 3.8)
|
52
|
+
rake (>= 12.0)
|
45
53
|
rspec-graphql_response!
|
54
|
+
super_diff (~> 0.6)
|
46
55
|
|
47
56
|
BUNDLED WITH
|
48
57
|
1.17.2
|
data/README.md
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
RSpec::GraphQLResponse provides a series of RSpec matchers, helper methods, and other configuration to help simplify
|
4
4
|
the testing of responses from the `graphql-ruby` gem and the `<GraphQLSchemaName>.execute` method.
|
5
5
|
|
6
|
+
## "Why Should I Use This?"
|
7
|
+
|
8
|
+
There are a number of built-in helper methods and matchers that will allow you to skip the copy & paste work of executing
|
9
|
+
a GraphQL Schema `.execute`. Additionally, there are custom matchers and other bits that will help simplify your work in
|
10
|
+
validating common peices of a graphql response.
|
11
|
+
|
12
|
+
Lastly, the work in this gem is geared toward customization for your own application's needs. Every API call used for building
|
13
|
+
the pieces of this gem are available to you, directly, in the `API / Development` documentation, below.
|
14
|
+
|
6
15
|
## Installation
|
7
16
|
|
8
17
|
Your app must have `graphql-ruby` and `rspec`. With that done, add this line to your application's Gemfile:
|
@@ -21,71 +30,60 @@ Or install it yourself as:
|
|
21
30
|
|
22
31
|
## Full Documentation
|
23
32
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Custom Matchers:
|
28
|
-
* [have_errors matcher](/docs/have_errors.md) - validates errors, or lack of, on
|
29
|
-
the GraphQL response
|
33
|
+
- [Release Notes](/RELEASE_NOTES.md)
|
34
|
+
- [Upgrade Guide](/UPGRADE.md)
|
30
35
|
|
31
|
-
|
32
|
-
* [operation](/docs/operation.md) - retrieves the results of a named operation
|
33
|
-
from the GraphQL response
|
36
|
+
The full documentation for RSpec::GraphQLResponse can be found in the `/docs` folder.
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
* [.add_matcher](/docs/add_matcher.md) - add a custom RSpec matcher to the
|
38
|
-
GraphQLResponse matchers
|
39
|
-
* [.add_validator](/docs/add_validator.md) - add a custom validator to be used
|
40
|
-
by the custom matchers
|
41
|
-
|
42
|
-
## Configuration
|
43
|
-
|
44
|
-
To get things rolling, add a configuration block to your `spec_helper.rb` (or other file that gets included in specs, as
|
45
|
-
desired). Within this block, you'll need to provide the GraphQL Schema to use for query execution.
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
RSpec::GraphQLResponse.configure |config| do
|
38
|
+
Configuration:
|
49
39
|
|
50
|
-
|
40
|
+
- [RSpec::GraphQLResponse.configure](/docs/configuration.md)
|
41
|
+
- [Spec Type :graphql](/docs/graphql_spec_type.md)
|
51
42
|
|
52
|
-
|
53
|
-
```
|
43
|
+
Custom Matchers:
|
54
44
|
|
55
|
-
|
45
|
+
- [have_errors](/docs/have_errors.md) - validates errors, or lack of, on the GraphQL response
|
46
|
+
- [have_operation](/docs/have_operation.md) - validates the presence of a specified graphql operation in the graphql response
|
56
47
|
|
57
|
-
|
58
|
-
a GraphQL Schema `.execute`. These include:
|
48
|
+
Context / Describe Helper Methods:
|
59
49
|
|
60
|
-
|
50
|
+
- [graphql_operation](/docs/execute_graphql.md) - the operation to execute (i.e query or mutation)
|
51
|
+
- [graphql_variables](/docs/execute_graphql.md) - a hash of variables the query expects
|
52
|
+
- [graphql_context](/docs/execute_graphql.md) - the `context` of a query or mutation's resolver
|
61
53
|
|
62
|
-
|
54
|
+
Spec Helper Methods:
|
63
55
|
|
64
|
-
|
56
|
+
- [execute_graphql](/docs/execute_graphql.md) - executes a graphql call with the registered schema, query, variables and context
|
57
|
+
- [response](/docs/response.md) - the response, as JSON, of the executed graphql query
|
58
|
+
- [response_data](/docs/response_data.md) - digs through the graphql response to return data from the specified node(s)
|
65
59
|
|
66
|
-
|
67
|
-
* `response`
|
68
|
-
* `operation`
|
60
|
+
API / Development
|
69
61
|
|
70
|
-
|
62
|
+
- [.add_matcher](/docs/add_matcher.md) - add a custom RSpec matcher to the GraphQLResponse matchers
|
63
|
+
- [.add_validator](/docs/add_validator.md) - add a custom validator to be used by the custom matchers
|
64
|
+
- [.add_helper](/docs/add_helper.md) - add helper methods to your specs, made avialable in `it` or `describe` / `context` blocks
|
71
65
|
|
72
|
-
|
66
|
+
## Getting Started
|
73
67
|
|
74
|
-
|
68
|
+
There are only a couple of bits you need to get started:
|
75
69
|
|
76
|
-
|
70
|
+
- configuration of a GraphQL Schema in [`RSpec::GraphQLResponse.configure`](/docs/configuration.md)
|
71
|
+
- the inclusion of [`type: :graphql`](/docs/graphql_spec_type.md) in your `RSpec.describe` call
|
77
72
|
|
78
73
|
```ruby
|
79
|
-
RSpec.
|
80
|
-
|
81
|
-
|
74
|
+
RSpec::GraphQLResponse.configure do |config|
|
75
|
+
config.graphql_schema = MyGraphQLSchema
|
76
|
+
end
|
82
77
|
|
78
|
+
RSpec.describe My::Cool::Thing, type: :graphql do
|
79
|
+
# ...
|
83
80
|
end
|
84
81
|
```
|
85
82
|
|
86
|
-
|
83
|
+
Beyond these two basic needs, understanding the reason for this gem's existence can be useful in figuring out what the gem
|
84
|
+
does, and what methods and options are available.
|
87
85
|
|
88
|
-
|
86
|
+
## How We Got Here
|
89
87
|
|
90
88
|
Executing a GraphQL call from RSpec is not the most challening code to write:
|
91
89
|
|
@@ -121,16 +119,14 @@ in your specs.
|
|
121
119
|
|
122
120
|
```ruby
|
123
121
|
RSpec.describe Some::Thing, type: :graphql do
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
name
|
130
|
-
}
|
122
|
+
graphql_operation <<-GQL
|
123
|
+
query ListCharacters{
|
124
|
+
characters {
|
125
|
+
id
|
126
|
+
name
|
131
127
|
}
|
132
|
-
|
133
|
-
|
128
|
+
}
|
129
|
+
GQL
|
134
130
|
|
135
131
|
it "executes the query" do
|
136
132
|
response = execute_graphql.to_h
|
@@ -147,16 +143,14 @@ way. The reduce this, `RSpec::GraphQLResponse` provides a built-in `response` he
|
|
147
143
|
|
148
144
|
```ruby
|
149
145
|
RSpec.describe Some::Thing, type: :graphql do
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
name
|
156
|
-
}
|
146
|
+
graphql_operation <<-GQL
|
147
|
+
query ListCharacters{
|
148
|
+
characters {
|
149
|
+
id
|
150
|
+
name
|
157
151
|
}
|
158
|
-
|
159
|
-
|
152
|
+
}
|
153
|
+
GQL
|
160
154
|
|
161
155
|
it "executes the query" do
|
162
156
|
expect(response).to include(
|
@@ -176,22 +170,20 @@ nested hash checking, use the built-in `operation` method to retrieve the `chara
|
|
176
170
|
|
177
171
|
```ruby
|
178
172
|
RSpec.describe Some::Thing, type: :graphql do
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
name
|
185
|
-
}
|
173
|
+
graphql_operation <<-GQL
|
174
|
+
query ListCharacters{
|
175
|
+
characters {
|
176
|
+
id
|
177
|
+
name
|
186
178
|
}
|
187
|
-
|
188
|
-
|
179
|
+
}
|
180
|
+
GQL
|
189
181
|
|
190
182
|
it "executes the query" do
|
191
183
|
characters = operation(:characters)
|
192
184
|
|
193
185
|
expect(characters).to include(
|
194
|
-
# ...
|
186
|
+
# ...
|
195
187
|
)
|
196
188
|
end
|
197
189
|
end
|
data/RELEASE_NOTES.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Release Notes
|
2
|
+
|
3
|
+
Release notes for various versions of RSpec::GraphQLResponse
|
4
|
+
|
5
|
+
See [the upgrade guide](/UPGRADE.md) for details on changes between versions and how to upgrade.
|
6
|
+
|
7
|
+
## v0.4.0 - Helper API change
|
8
|
+
|
9
|
+
### Breaking Changes
|
10
|
+
|
11
|
+
The helper `graphql_query` was renamed to `graphql_operation` to better communicate the use of the helper. Naming the helper with `_query` lead to an association that its use was meant for GraphQL query operations and could not also be used for a mutation.
|
12
|
+
|
13
|
+
## v0.2.0 - GraphQL Configuration DSL and Refactorings
|
14
|
+
|
15
|
+
Misc changes and corrections, some new features, and generally trying to create a more robust
|
16
|
+
and usable experience, right out of the box.
|
17
|
+
|
18
|
+
### New Features
|
19
|
+
|
20
|
+
- Significantly improved documentation
|
21
|
+
- `have_operation` matcher
|
22
|
+
- GraphQL configuration DSL
|
23
|
+
- `graphql_query`
|
24
|
+
- `graphql_variables`
|
25
|
+
- `graphql_context`
|
26
|
+
- Describe/Context level RSpec helper methods via `.add_context_helper` DSL
|
27
|
+
|
28
|
+
### Breaking Changes
|
29
|
+
|
30
|
+
This release changes the graphql query, variables and context configuration away from `let` vars
|
31
|
+
and into a proper DSL.
|
32
|
+
|
33
|
+
### Bug Fixes
|
34
|
+
|
35
|
+
Lots of misc bug fixes, including caching of values, ensuring things work in nested contexts, etc.
|
36
|
+
|
37
|
+
## v0.1.0 - Initial Release
|
38
|
+
|
39
|
+
Early beta work to get this out the door and begin adoption
|
40
|
+
|
41
|
+
- `have_errors` matcher
|
42
|
+
- `operation` helper
|
43
|
+
- `response` helper
|
44
|
+
- `execute_graphql` helper
|
45
|
+
- DSL for adding custom matchers, validators, and helpers
|