gruf-rspec 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 236b6540ce7b46849e1555545c2d33077af0cb551799f172f241de2e2d618699
4
- data.tar.gz: f7e800ef23126d40077fa324630ce5645743e9673a602fb7dfcb4e08a8a55282
3
+ metadata.gz: 183210380a3d9ee581da3cd15372d2c7ed2a3e75614dce61799a4ca53f413bc3
4
+ data.tar.gz: 742b03b5cfba9551bb39e7ce005d2a68ff5bba073279ab86e4fc2604e838871b
5
5
  SHA512:
6
- metadata.gz: 3b1ba006790a428f9b55fce3027e7d2f2fd9f62f07c241a7af4dd19479a58c64e23275ded044d305453801801a9333b92db8927195a3f5f4f5b1aff6eceb5789
7
- data.tar.gz: 80138e96b2df8575553f8f186d6968502292cef59f4e941420ac42cb62a4e26eed88d231a6c9adc4218f05604b2377ab2d6cfeefe2f8dcf86c3ea874fb61b12e
6
+ metadata.gz: 49c856a13070558d1141411d00985ae6a1eac96627fc5bdb1e26927ed1cfc4a0447f24d44c6014d678bb3e8f5bea4d0ac596f73c816e3c79ea5fd060f763db1f
7
+ data.tar.gz: f733d50ca82902e5e64bdbf8f9c5207b8b4b1451206474d286af4d7a7d7d58de48aa2c40a2484b00c326b45196b1ea56cd7e83c96e90968bb40dd2e65ca03979
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@ Changelog for the gruf-rspec gem.
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 0.6.0
6
+
7
+ - Add better support for Gruf 2.15+ autoloading in a Rails test environment
8
+ - Use zeitwerk for autoloading in this library
9
+
5
10
  ### 0.5.0
6
11
 
7
12
  - Add support for Ruby 3.1
@@ -14,7 +19,7 @@ Changelog for the gruf-rspec gem.
14
19
 
15
20
  ### 0.3.0
16
21
 
17
- - [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
22
+ - [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
18
23
  - Drop support for Ruby < 2.6, add 2.7 tests
19
24
  - Update rubocop to 1.0
20
25
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/bigcommerce/gruf-rspec/tree/main.svg?style=svg)](https://circleci.com/gh/bigcommerce/gruf-rspec/tree/main) [![Gem Version](https://badge.fury.io/rb/gruf-rspec.svg)](https://badge.fury.io/rb/gruf-rspec) [![Documentation](https://inch-ci.org/github/bigcommerce/gruf-rspec.svg?branch=main)](https://inch-ci.org/github/bigcommerce/gruf-rspec?branch=main) [![Maintainability](https://api.codeclimate.com/v1/badges/db2d134a7148dde045b7/maintainability)](https://codeclimate.com/github/bigcommerce/gruf-rspec/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/db2d134a7148dde045b7/test_coverage)](https://codeclimate.com/github/bigcommerce/gruf-rspec/test_coverage)
4
4
 
5
- Assistance helpers and custom type for easy testing [Gruf](https://github.com/bigcommerce/gruf) controllers with
5
+ Assistance helpers and custom type for easy testing [Gruf](https://github.com/bigcommerce/gruf) controllers with
6
6
  [RSpec](https://github.com/rspec/rspec).
7
7
 
8
8
  ## Installation
@@ -10,12 +10,6 @@ Assistance helpers and custom type for easy testing [Gruf](https://github.com/bi
10
10
  ```ruby
11
11
  gem 'gruf-rspec'
12
12
  ```
13
-
14
- Then add the following code to your `spec_helper.rb`:
15
-
16
- ```ruby
17
- require 'gruf/rspec'
18
- ```
19
13
 
20
14
  Note that this gem requires at least Ruby 2.7+, Gruf 2.5.1+, and RSpec 3.8+.
21
15
 
@@ -28,13 +22,13 @@ and the active_call_options. The third argument is optional.
28
22
 
29
23
  ## Example
30
24
 
31
- Let's assume you have a gruf controller named `ThingController` that is bound to the gRPC
25
+ Let's assume you have a gruf controller named `ThingController` that is bound to the gRPC
32
26
  service `Rpc::Things::Service`. That has a method `GetThing`:
33
27
 
34
28
  ```ruby
35
29
  class ThingController < Gruf::Controllers::Base
36
30
  bind ::Rpc::Things::Service
37
-
31
+
38
32
  def get_thing
39
33
  Rpc::GetThingResponse.new(id: request.message.id)
40
34
  end
@@ -45,7 +39,7 @@ To test it, you'd create `spec/rpc/thing_controller_spec.rb`:
45
39
 
46
40
  ```ruby
47
41
  describe ThingController do
48
- describe '.get_thing' do
42
+ describe '#get_thing' do
49
43
  let(:request_proto) { Rpc::GetThingRequest.new(id: rand(1..100)) }
50
44
  let(:metadata) {
51
45
  { 'user_id' => 'axj42i' }
@@ -53,8 +47,8 @@ describe ThingController do
53
47
 
54
48
  subject { run_rpc(:GetThing, request_proto, active_call_options: { metadata: metadata }) }
55
49
 
56
- it 'will return the thing' do
57
- expect(subject).to be_a(Rpc::GetThingResponse)
50
+ it 'returns the thing' do
51
+ expect(subject).to be_a_successful_rpc
58
52
  expect(subject.id).to eq request_proto.id
59
53
  end
60
54
  end
@@ -64,9 +58,9 @@ end
64
58
  Alternatively, you can pass a block:
65
59
 
66
60
  ```ruby
67
- it 'will return the thing' do
61
+ it 'returns the thing' do
68
62
  run_rpc(:GetThing, request_proto) do |resp|
69
- expect(resp).to be_a(Rpc::GetThingResponse)
63
+ expect(resp).to be_a_successful_rpc
70
64
  expect(resp.id).to eq request_proto.id
71
65
  end
72
66
  end
@@ -80,7 +74,7 @@ Note that you can also access the bound gRPC service class:
80
74
  it 'binds the service correctly' do
81
75
  expect(grpc_bound_service).to eq Rpc::Things::Service
82
76
  end
83
- ```
77
+ ```
84
78
 
85
79
  ### Matching Errors
86
80
 
@@ -89,9 +83,9 @@ You can match against errors as well:
89
83
  ```ruby
90
84
  describe 'testing an error' do
91
85
  let(:request_proto) { Rpc::GetThingRequest.new(id: rand(1..100)) }
92
-
86
+
93
87
  subject { run_rpc(:GetThing, request_proto) }
94
-
88
+
95
89
  it 'should fail with the appropriate error' do
96
90
  expect { subject }.to raise_rpc_error(GRPC::InvalidArgument)
97
91
  end
@@ -105,11 +99,11 @@ it 'should fail with the appropriate error code' do
105
99
  expect { subject }.to raise_rpc_error(GRPC::InvalidArgument).with_serialized { |err|
106
100
  expect(err).to be_a(MyCustomErrorClass)
107
101
  expect(err.error_code).to eq 'invalid_request'
108
-
102
+
109
103
  fe = err.field_errors.first
110
104
  expect(fe.field_name).to eq 'name'
111
105
  expect(fe.error_code).to eq 'invalid_name'
112
- expect(fe.error_message).to eq
106
+ expect(fe.error_message).to eq 'That name is already taken!'
113
107
  }
114
108
  end
115
109
  ```
@@ -117,7 +111,6 @@ end
117
111
  Note that when using `with_serialized`, you _must_ pass the block with `{ }`, not using
118
112
  `do` and `end`.
119
113
 
120
-
121
114
  ### RSpec Controller Matcher Configuration
122
115
 
123
116
  By default, the type matcher for Gruf controllers matches in `/spec/rpc`. You can customize this by configuring it
@@ -129,7 +122,7 @@ Gruf::Rspec.configure do |c|
129
122
  end
130
123
  ```
131
124
 
132
- Alternatively, you can pass configuration of the path via ENV. For example, where
125
+ Alternatively, you can pass configuration of the path via ENV. For example, where
133
126
  `RPC_SPEC_PATH="/spec/rpc_controllers"` is set in a `.env` file:
134
127
 
135
128
  ```bash
data/gruf-rspec.gemspec CHANGED
@@ -15,9 +15,7 @@
15
15
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
- lib = File.expand_path('lib', __dir__)
19
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
- require 'gruf/rspec/version'
18
+ require_relative 'lib/gruf/rspec/version'
21
19
 
22
20
  Gem::Specification.new do |spec|
23
21
  spec.name = 'gruf-rspec'
@@ -31,9 +29,10 @@ Gem::Specification.new do |spec|
31
29
  spec.homepage = 'https://github.com/bigcommerce/gruf-rspec'
32
30
 
33
31
  spec.required_ruby_version = '>= 2.7'
32
+ spec.metadata['rubygems_mfa_required'] = 'true'
34
33
 
35
34
  spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-rspec.gemspec']
36
- spec.require_paths = ['lib']
35
+ spec.require_paths = %w[lib]
37
36
 
38
37
  spec.add_development_dependency 'bundler-audit', '>= 0.6'
39
38
  spec.add_development_dependency 'pry', '>= 0.13'
@@ -43,4 +42,5 @@ Gem::Specification.new do |spec|
43
42
 
44
43
  spec.add_runtime_dependency 'gruf', '~> 2.5', '>= 2.5.1'
45
44
  spec.add_runtime_dependency 'rspec', '>= 3.8'
45
+ spec.add_runtime_dependency 'zeitwerk', '>= 2'
46
46
  end
@@ -15,9 +15,6 @@
15
15
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
- require_relative 'authentication_hydrators/base'
19
- require_relative 'authentication_hydrators/basic'
20
-
21
18
  module Gruf
22
19
  module Rspec
23
20
  ##
@@ -15,8 +15,6 @@
15
15
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
- require_relative 'metadata_factory'
19
-
20
18
  module Gruf
21
19
  module Rspec
22
20
  ##
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2022-present, BigCommerce Pty. Ltd. All rights reserved
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ # Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ #
18
+ module Gruf
19
+ module Rspec
20
+ ##
21
+ # Rails integration for gruf-rspec
22
+ #
23
+ class Railtie < ::Rails::Railtie
24
+ initializer 'gruf-rspec.initializer' do |_app|
25
+ config.after_initialize do
26
+ ::Gruf.autoloaders.load!(controllers_path: ::Gruf.controllers_path) if ::Gruf.respond_to?(:autoloaders)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -17,6 +17,6 @@
17
17
  #
18
18
  module Gruf
19
19
  module Rspec
20
- VERSION = '0.5.0'
20
+ VERSION = '0.6.0'
21
21
  end
22
22
  end
data/lib/gruf/rspec.rb CHANGED
@@ -26,10 +26,15 @@ rescue LoadError # old rspec compat
26
26
  GRUF_RSPEC_RUNNER = Spec::Runner
27
27
  end
28
28
 
29
- require_relative 'rspec/version'
30
- require_relative 'rspec/configuration'
31
- require_relative 'rspec/helpers'
32
- require_relative 'rspec/error_matcher'
29
+ # use Zeitwerk to lazily autoload all the files in the lib directory
30
+ require 'zeitwerk'
31
+ lib_path = File.dirname(__dir__)
32
+ loader = ::Zeitwerk::Loader.new
33
+ loader.tag = 'gruf-rspec'
34
+ loader.inflector = ::Zeitwerk::GemInflector.new(__FILE__)
35
+ loader.ignore("#{lib_path}/gruf/rspec/railtie.rb")
36
+ loader.push_dir(lib_path)
37
+ loader.setup
33
38
 
34
39
  ##
35
40
  # Base gruf module
@@ -45,6 +50,14 @@ end
45
50
 
46
51
  Gruf::Rspec.reset # initial reset
47
52
 
53
+ # Attempt to load railtie if we're in a rails environment. This assists with autoloading in a rails rspec context
54
+ begin
55
+ require 'rails'
56
+ rescue LoadError
57
+ nil
58
+ end
59
+ require_relative 'rspec/railtie' if defined?(::Rails::Railtie)
60
+
48
61
  GRUF_RSPEC_RUNNER.configure do |config|
49
62
  config.include Gruf::Rspec::Helpers
50
63
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2022-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '3.8'
117
+ - !ruby/object:Gem::Dependency
118
+ name: zeitwerk
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '2'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '2'
117
131
  description: RSpec assistance library for gruf, including testing helpers
118
132
  email:
119
133
  - splittingred@gmail.com
@@ -132,11 +146,13 @@ files:
132
146
  - lib/gruf/rspec/error_matcher.rb
133
147
  - lib/gruf/rspec/helpers.rb
134
148
  - lib/gruf/rspec/metadata_factory.rb
149
+ - lib/gruf/rspec/railtie.rb
135
150
  - lib/gruf/rspec/version.rb
136
151
  homepage: https://github.com/bigcommerce/gruf-rspec
137
152
  licenses:
138
153
  - MIT
139
- metadata: {}
154
+ metadata:
155
+ rubygems_mfa_required: 'true'
140
156
  post_install_message:
141
157
  rdoc_options: []
142
158
  require_paths:
@@ -152,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
168
  - !ruby/object:Gem::Version
153
169
  version: '0'
154
170
  requirements: []
155
- rubygems_version: 3.3.3
171
+ rubygems_version: 3.3.7
156
172
  signing_key:
157
173
  specification_version: 4
158
174
  summary: RSpec assistance library for gruf