rspec-graphql_response 0.1.0 → 0.4.1

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +14 -0
  3. data/.gitignore +3 -0
  4. data/.gituprc +128 -0
  5. data/Gemfile.lock +16 -7
  6. data/README.md +64 -72
  7. data/RELEASE_NOTES.md +45 -0
  8. data/UPGRADE.md +41 -0
  9. data/docs/add_helper.md +94 -0
  10. data/docs/add_validator.md +168 -1
  11. data/docs/configuration.md +12 -0
  12. data/docs/execute_graphql.md +50 -0
  13. data/docs/graphql_spec_type.md +14 -0
  14. data/docs/have_operation.md +46 -0
  15. data/docs/operation.md +1 -36
  16. data/docs/response.md +1 -0
  17. data/docs/response_data.md +146 -0
  18. data/lib/rspec/graphql_response.rb +2 -1
  19. data/lib/rspec/graphql_response/dig_dug/dig_dug.rb +83 -0
  20. data/lib/rspec/graphql_response/helpers.rb +35 -7
  21. data/lib/rspec/graphql_response/helpers/execute_graphql.rb +14 -1
  22. data/lib/rspec/graphql_response/helpers/graphql_context.rb +3 -0
  23. data/lib/rspec/graphql_response/helpers/graphql_operation.rb +3 -0
  24. data/lib/rspec/graphql_response/helpers/graphql_variables.rb +3 -0
  25. data/lib/rspec/graphql_response/helpers/operation.rb +1 -0
  26. data/lib/rspec/graphql_response/helpers/response_data.rb +13 -0
  27. data/lib/rspec/graphql_response/matchers.rb +1 -0
  28. data/lib/rspec/graphql_response/matchers/have_errors.rb +2 -2
  29. data/lib/rspec/graphql_response/matchers/have_operation.rb +23 -0
  30. data/lib/rspec/graphql_response/validators.rb +6 -0
  31. data/lib/rspec/graphql_response/validators/have_operation.rb +24 -0
  32. data/lib/rspec/graphql_response/version.rb +1 -1
  33. data/rspec-graphql_response.gemspec +3 -2
  34. metadata +52 -21
  35. data/.travis.yml +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d1e0d86474c6b5f5e99c3d19e3d1645fe35819d5a47a4fd7007af9c9a5700e
4
- data.tar.gz: d27339cca95c74fdb174fa0ca6a43116039b449e0b22ef6397ccd76e8eb472d1
3
+ metadata.gz: 647c52ffa5ae347bc9c2166bd94af15ee82556d10f37fa5a11a0cf0229d40b31
4
+ data.tar.gz: a93873e4d4a40a9a4702026321d96d913056188dd51eec86836232add5e7c4b7
5
5
  SHA512:
6
- metadata.gz: b427ec094b4a8e19865e3d610a14abb32625189f7ea190ca61dbcde61e8582abca4464980e2790bb2d30b8ecbb83912034f4a95bcc1cd8744410328a646ad755
7
- data.tar.gz: d0864628a5e6beb9096fe8901f67dd6f75d824af26631e1b66ea97894bd30da4061f6ceb25ffc692461a1e54a50f7e7c56405f89cce6275e919d624c9dd29dc8
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
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # ignore the resulting .gem file from gem build
14
+ rspec-graphql_response*.gem
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.0)
5
- rspec
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.4)
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
- graphql (~> 1.12)
42
- pry
43
- pry-byebug
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
- The full documentation for RSpec::GraphQLResponse can be found in the `/docs`
25
- folder.
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
- Helper Methods:
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
- Internal API / Development
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
- config.graphql_schema = MyGraphQLSchema
40
+ - [RSpec::GraphQLResponse.configure](/docs/configuration.md)
41
+ - [Spec Type :graphql](/docs/graphql_spec_type.md)
51
42
 
52
- end
53
- ```
43
+ Custom Matchers:
54
44
 
55
- ## Getting Started
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
- There are a number of built-in helper methods and matchers that will allow you to skip the copy & paste work of executing
58
- a GraphQL Schema `.execute`. These include:
48
+ Context / Describe Helper Methods:
59
49
 
60
- Spec types:
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
- * `type: :graphql`
54
+ Spec Helper Methods:
63
55
 
64
- Helper methods:
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
- * `execute_graphql`
67
- * `response`
68
- * `operation`
60
+ API / Development
69
61
 
70
- Matchers:
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
- * `have_errors`
66
+ ## Getting Started
73
67
 
74
- ### The `:graphql` Spec Type
68
+ There are only a couple of bits you need to get started:
75
69
 
76
- To use these custom helpers and matchers, you need to specificy `type: :graphql` as part of your spec's description. For exmaple,
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.describe Some::Thing, type: :graphql do
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
- With this `type` set, your specs will have access to all of the `RSpec::GraphQLResponse` code.
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
- ### Helper Methods
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
- let(:query) do
125
- <<-GQL
126
- query ListCharacters{
127
- characters {
128
- id
129
- name
130
- }
122
+ graphql_operation <<-GQL
123
+ query ListCharacters{
124
+ characters {
125
+ id
126
+ name
131
127
  }
132
- GQL
133
- end
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
- let(:query) do
151
- <<-GQL
152
- query {
153
- characters {
154
- id
155
- name
156
- }
146
+ graphql_operation <<-GQL
147
+ query ListCharacters{
148
+ characters {
149
+ id
150
+ name
157
151
  }
158
- GQL
159
- end
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
- let(:query) do
180
- <<-GQL
181
- query {
182
- characters {
183
- id
184
- name
185
- }
173
+ graphql_operation <<-GQL
174
+ query ListCharacters{
175
+ characters {
176
+ id
177
+ name
186
178
  }
187
- GQL
188
- end
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