gruf-rspec 0.5.0 → 1.0.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: 6291a6cf9290f5a961f9fe4aaa14cab581d4e6f8496165d9d615554c31aadf2a
4
+ data.tar.gz: eed0811eb88ff1a57d02b6c03e523eef23859b69b1d9cff9362cdd08c6175d78
5
5
  SHA512:
6
- metadata.gz: 3b1ba006790a428f9b55fce3027e7d2f2fd9f62f07c241a7af4dd19479a58c64e23275ded044d305453801801a9333b92db8927195a3f5f4f5b1aff6eceb5789
7
- data.tar.gz: 80138e96b2df8575553f8f186d6968502292cef59f4e941420ac42cb62a4e26eed88d231a6c9adc4218f05604b2377ab2d6cfeefe2f8dcf86c3ea874fb61b12e
6
+ metadata.gz: 235f0f22e3bfde97bb808c683848c5a5ec396c9d4b194b2aa6071c0a251903365344ba0e6d9de05614ebbed9dc634172dd0b7484f88bce2966eb523bf15487ec
7
+ data.tar.gz: 7cb35d4584731c5f733de85260feb13154cb9f85b714ce6e19e88054d002f83fc0a20dcb7d696b37b54e56759d013ce30419ab4028ce0a0589b69e7b0e3e2859
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@ Changelog for the gruf-rspec gem.
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 1.0.0
6
+
7
+ - Add support for Ruby 3.2, 3.3
8
+ - Drop support for Ruby 2.7 (EOL March 2023)
9
+
10
+ ### 0.6.0
11
+
12
+ - Add better support for Gruf 2.15+ autoloading in a Rails test environment
13
+ - Use zeitwerk for autoloading in this library
14
+
5
15
  ### 0.5.0
6
16
 
7
17
  - Add support for Ruby 3.1
@@ -14,7 +24,7 @@ Changelog for the gruf-rspec gem.
14
24
 
15
25
  ### 0.3.0
16
26
 
17
- - [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
27
+ - [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
18
28
  - Drop support for Ruby < 2.6, add 2.7 tests
19
29
  - Update rubocop to 1.0
20
30
 
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,14 +10,8 @@ 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
13
 
16
- ```ruby
17
- require 'gruf/rspec'
18
- ```
19
-
20
- Note that this gem requires at least Ruby 2.7+, Gruf 2.5.1+, and RSpec 3.8+.
14
+ Note that this gem requires at least Ruby 3.0+, Gruf 2.5.1+, and RSpec 3.8+.
21
15
 
22
16
  ## Usage
23
17
 
@@ -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,10 +83,10 @@ 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
-
95
- it 'should fail with the appropriate error' do
88
+
89
+ it 'fails with the appropriate error' do
96
90
  expect { subject }.to raise_rpc_error(GRPC::InvalidArgument)
97
91
  end
98
92
  end
@@ -101,15 +95,15 @@ end
101
95
  Or further, even check your serialized error that is passed in metadata:
102
96
 
103
97
  ```ruby
104
- it 'should fail with the appropriate error code' do
98
+ it 'fails 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'
@@ -30,17 +28,14 @@ Gem::Specification.new do |spec|
30
28
  spec.description = 'RSpec assistance library for gruf, including testing helpers'
31
29
  spec.homepage = 'https://github.com/bigcommerce/gruf-rspec'
32
30
 
33
- spec.required_ruby_version = '>= 2.7'
31
+ spec.required_ruby_version = '>= 3.0', '< 4'
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']
37
-
38
- spec.add_development_dependency 'bundler-audit', '>= 0.6'
39
- spec.add_development_dependency 'pry', '>= 0.13'
40
- spec.add_development_dependency 'rspec_junit_formatter', '>= 0.4'
41
- spec.add_development_dependency 'rubocop', '>= 0.82'
42
- spec.add_development_dependency 'simplecov', '>= 0.15'
35
+ spec.require_paths = %w[lib]
43
36
 
44
37
  spec.add_runtime_dependency 'gruf', '~> 2.5', '>= 2.5.1'
38
+ spec.add_runtime_dependency 'rake', '>= 12.3'
45
39
  spec.add_runtime_dependency 'rspec', '>= 3.8'
40
+ spec.add_runtime_dependency 'zeitwerk', '>= 2'
46
41
  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 = '1.0.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,119 +1,77 @@
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: 1.0.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: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler-audit
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0.6'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
14
+ name: gruf
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0.13'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
17
+ - - "~>"
39
18
  - !ruby/object:Gem::Version
40
- version: '0.13'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec_junit_formatter
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
19
+ version: '2.5'
45
20
  - - ">="
46
21
  - !ruby/object:Gem::Version
47
- version: '0.4'
48
- type: :development
22
+ version: 2.5.1
23
+ type: :runtime
49
24
  prerelease: false
50
25
  version_requirements: !ruby/object:Gem::Requirement
51
26
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0.4'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
27
+ - - "~>"
60
28
  - !ruby/object:Gem::Version
61
- version: '0.82'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
29
+ version: '2.5'
66
30
  - - ">="
67
31
  - !ruby/object:Gem::Version
68
- version: '0.82'
32
+ version: 2.5.1
69
33
  - !ruby/object:Gem::Dependency
70
- name: simplecov
34
+ name: rake
71
35
  requirement: !ruby/object:Gem::Requirement
72
36
  requirements:
73
37
  - - ">="
74
38
  - !ruby/object:Gem::Version
75
- version: '0.15'
76
- type: :development
39
+ version: '12.3'
40
+ type: :runtime
77
41
  prerelease: false
78
42
  version_requirements: !ruby/object:Gem::Requirement
79
43
  requirements:
80
44
  - - ">="
81
45
  - !ruby/object:Gem::Version
82
- version: '0.15'
46
+ version: '12.3'
83
47
  - !ruby/object:Gem::Dependency
84
- name: gruf
48
+ name: rspec
85
49
  requirement: !ruby/object:Gem::Requirement
86
50
  requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.5'
90
51
  - - ">="
91
52
  - !ruby/object:Gem::Version
92
- version: 2.5.1
53
+ version: '3.8'
93
54
  type: :runtime
94
55
  prerelease: false
95
56
  version_requirements: !ruby/object:Gem::Requirement
96
57
  requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '2.5'
100
58
  - - ">="
101
59
  - !ruby/object:Gem::Version
102
- version: 2.5.1
60
+ version: '3.8'
103
61
  - !ruby/object:Gem::Dependency
104
- name: rspec
62
+ name: zeitwerk
105
63
  requirement: !ruby/object:Gem::Requirement
106
64
  requirements:
107
65
  - - ">="
108
66
  - !ruby/object:Gem::Version
109
- version: '3.8'
67
+ version: '2'
110
68
  type: :runtime
111
69
  prerelease: false
112
70
  version_requirements: !ruby/object:Gem::Requirement
113
71
  requirements:
114
72
  - - ">="
115
73
  - !ruby/object:Gem::Version
116
- version: '3.8'
74
+ version: '2'
117
75
  description: RSpec assistance library for gruf, including testing helpers
118
76
  email:
119
77
  - splittingred@gmail.com
@@ -132,11 +90,13 @@ files:
132
90
  - lib/gruf/rspec/error_matcher.rb
133
91
  - lib/gruf/rspec/helpers.rb
134
92
  - lib/gruf/rspec/metadata_factory.rb
93
+ - lib/gruf/rspec/railtie.rb
135
94
  - lib/gruf/rspec/version.rb
136
95
  homepage: https://github.com/bigcommerce/gruf-rspec
137
96
  licenses:
138
97
  - MIT
139
- metadata: {}
98
+ metadata:
99
+ rubygems_mfa_required: 'true'
140
100
  post_install_message:
141
101
  rdoc_options: []
142
102
  require_paths:
@@ -145,14 +105,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
105
  requirements:
146
106
  - - ">="
147
107
  - !ruby/object:Gem::Version
148
- version: '2.7'
108
+ version: '3.0'
109
+ - - "<"
110
+ - !ruby/object:Gem::Version
111
+ version: '4'
149
112
  required_rubygems_version: !ruby/object:Gem::Requirement
150
113
  requirements:
151
114
  - - ">="
152
115
  - !ruby/object:Gem::Version
153
116
  version: '0'
154
117
  requirements: []
155
- rubygems_version: 3.3.3
118
+ rubygems_version: 3.5.3
156
119
  signing_key:
157
120
  specification_version: 4
158
121
  summary: RSpec assistance library for gruf