gruf-rspec 0.1.2 → 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 +27 -0
- data/README.md +27 -6
- data/gruf-rspec.gemspec +14 -10
- data/lib/gruf/rspec.rb +11 -3
- data/lib/gruf/rspec/authentication_hydrators/base.rb +2 -0
- data/lib/gruf/rspec/authentication_hydrators/basic.rb +2 -0
- data/lib/gruf/rspec/configuration.rb +7 -3
- data/lib/gruf/rspec/error_matcher.rb +3 -1
- data/lib/gruf/rspec/helpers.rb +5 -0
- data/lib/gruf/rspec/metadata_factory.rb +2 -0
- data/lib/gruf/rspec/version.rb +3 -1
- metadata +50 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da3a95acbe4bf299a1d82f383b43361bdf204473916d06942850fe4fcad330f1
|
|
4
|
+
data.tar.gz: bf96d2fa48d250c87a660873bbb8568e019e99983aaba8d783688514bec5bd18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f73ab1c615fc25f28be00829d70994a54b16bde6b99a2382dfd5f08fc804c863ac0114c44ae9e2ec21be344a694f4586c5979ca2caff99c7800f8fda51ae954f
|
|
7
|
+
data.tar.gz: 66ea42f5022790b21e539c155d809c74e63c1dd13604a7cf39aef085216b92817f3f69fc8eceace95579a7b4486597397fdb5e1fe658e79db73a4ba75405a191
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@ Changelog for the gruf-rspec gem.
|
|
|
2
2
|
|
|
3
3
|
### Pending release
|
|
4
4
|
|
|
5
|
+
### 0.4.0
|
|
6
|
+
|
|
7
|
+
- Remove unnecessarily strict dev dependencies
|
|
8
|
+
- Adds support for Ruby 3.0 into test suite
|
|
9
|
+
|
|
10
|
+
### 0.3.0
|
|
11
|
+
|
|
12
|
+
- [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
|
|
13
|
+
- Drop support for Ruby < 2.6, add 2.7 tests
|
|
14
|
+
- Update rubocop to 1.0
|
|
15
|
+
|
|
16
|
+
### 0.2.2
|
|
17
|
+
|
|
18
|
+
* Loosen rspec dependency
|
|
19
|
+
|
|
20
|
+
### 0.2.1
|
|
21
|
+
|
|
22
|
+
* Loosen rack dependency
|
|
23
|
+
|
|
24
|
+
### 0.2.0
|
|
25
|
+
|
|
26
|
+
* Deprecate support for Ruby < 2.4
|
|
27
|
+
|
|
28
|
+
### 0.1.3
|
|
29
|
+
|
|
30
|
+
* Add ability to include metadata in rpc callsa
|
|
31
|
+
|
|
5
32
|
### 0.1.2
|
|
6
33
|
|
|
7
34
|
* Fix issue with RSPEC_NAMESPACE conflicts with other gems
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# gruf-rspec
|
|
2
2
|
|
|
3
|
-
[](https://circleci.com/gh/bigcommerce/gruf-rspec/tree/main) [](https://badge.fury.io/rb/gruf-rspec) [](https://inch-ci.org/github/bigcommerce/gruf-rspec?branch=main)
|
|
4
4
|
|
|
5
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).
|
|
@@ -17,12 +17,13 @@ Then add the following code to your `spec_helper.rb`:
|
|
|
17
17
|
require 'gruf/rspec'
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Note that this gem requires at least Gruf 2.5.1
|
|
20
|
+
Note that this gem requires at least Ruby 2.6+, Gruf 2.5.1+, and RSpec 3.8+.
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
* Add a test for a Gruf controller in `spec/rpc`
|
|
25
|
-
* Run the `run_rpc` method with
|
|
25
|
+
* Run the `run_rpc` method with three args: The gRPC method name, the request object
|
|
26
|
+
and the active_call_options. The third argument is optional.
|
|
26
27
|
* Validate the response
|
|
27
28
|
|
|
28
29
|
## Example
|
|
@@ -46,9 +47,12 @@ To test it, you'd create `spec/rpc/thing_controller_spec.rb`:
|
|
|
46
47
|
describe ThingController do
|
|
47
48
|
describe '.get_thing' do
|
|
48
49
|
let(:request_proto) { Rpc::GetThingRequest.new(id: rand(1..100)) }
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
let(:metadata) {
|
|
51
|
+
{ 'user_id' => 'axj42i' }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
subject { run_rpc(:GetThing, request_proto, active_call_options: { metadata: metadata }) }
|
|
55
|
+
|
|
52
56
|
it 'will return the thing' do
|
|
53
57
|
expect(subject).to be_a(Rpc::GetThingResponse)
|
|
54
58
|
expect(subject.id).to eq request_proto.id
|
|
@@ -125,6 +129,23 @@ Gruf::Rspec.configure do |c|
|
|
|
125
129
|
end
|
|
126
130
|
```
|
|
127
131
|
|
|
132
|
+
Alternatively, you can pass configuration of the path via ENV. For example, where
|
|
133
|
+
`RPC_SPEC_PATH="/spec/rpc_controllers"` is set in a `.env` file:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
bundle exec dotenv rspec
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or, add `require: false` to the gemspec for the `gruf-rspec` gem, and then explicitly require it after setting the ENV
|
|
140
|
+
var:
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
Dotenv.load # assuming the .env file has the RPC_SPEC_PATH var set
|
|
144
|
+
# or:
|
|
145
|
+
ENV['RPC_SPEC_PATH'] = '/spec/rpc_controllers'
|
|
146
|
+
require 'gruf/rspec'
|
|
147
|
+
```
|
|
148
|
+
|
|
128
149
|
## License
|
|
129
150
|
|
|
130
151
|
Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
data/gruf-rspec.gemspec
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -13,7 +15,7 @@
|
|
|
13
15
|
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
14
16
|
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
15
17
|
#
|
|
16
|
-
lib = File.expand_path('
|
|
18
|
+
lib = File.expand_path('lib', __dir__)
|
|
17
19
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
18
20
|
require 'gruf/rspec/version'
|
|
19
21
|
|
|
@@ -24,19 +26,21 @@ Gem::Specification.new do |spec|
|
|
|
24
26
|
spec.email = ['splittingred@gmail.com']
|
|
25
27
|
spec.license = 'MIT'
|
|
26
28
|
|
|
27
|
-
spec.summary =
|
|
28
|
-
spec.description =
|
|
29
|
+
spec.summary = 'RSpec assistance library for gruf'
|
|
30
|
+
spec.description = 'RSpec assistance library for gruf, including testing helpers'
|
|
29
31
|
spec.homepage = 'https://github.com/bigcommerce/gruf-rspec'
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
spec.required_ruby_version = '>= 2.6'
|
|
34
|
+
|
|
33
35
|
spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-rspec.gemspec']
|
|
34
36
|
spec.require_paths = ['lib']
|
|
35
37
|
|
|
36
|
-
spec.add_development_dependency 'bundler', '
|
|
37
|
-
spec.add_development_dependency '
|
|
38
|
-
spec.add_development_dependency '
|
|
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'
|
|
39
43
|
|
|
40
|
-
spec.
|
|
41
|
-
spec.
|
|
44
|
+
spec.add_runtime_dependency 'gruf', '~> 2.5', '>= 2.5.1'
|
|
45
|
+
spec.add_runtime_dependency 'rspec', '>= 3.8'
|
|
42
46
|
end
|
data/lib/gruf/rspec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -29,7 +31,13 @@ require_relative 'rspec/configuration'
|
|
|
29
31
|
require_relative 'rspec/helpers'
|
|
30
32
|
require_relative 'rspec/error_matcher'
|
|
31
33
|
|
|
34
|
+
##
|
|
35
|
+
# Base gruf module
|
|
36
|
+
#
|
|
32
37
|
module Gruf
|
|
38
|
+
##
|
|
39
|
+
# Base gruf-rspec module
|
|
40
|
+
#
|
|
33
41
|
module Rspec
|
|
34
42
|
extend Gruf::Rspec::Configuration
|
|
35
43
|
end
|
|
@@ -45,16 +53,16 @@ GRUF_RSPEC_RUNNER.configure do |config|
|
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
config.before(:each, type: :gruf_controller) do
|
|
48
|
-
define_singleton_method :run_rpc do |method_name, request, &block|
|
|
56
|
+
define_singleton_method :run_rpc do |method_name, request, active_call_options: {}, &block|
|
|
49
57
|
@gruf_controller = described_class.new(
|
|
50
58
|
method_key: method_name.to_s.underscore.to_sym,
|
|
51
59
|
service: grpc_bound_service,
|
|
52
60
|
rpc_desc: grpc_bound_service.rpc_descs[method_name.to_sym],
|
|
53
|
-
active_call: grpc_active_call,
|
|
61
|
+
active_call: grpc_active_call(active_call_options),
|
|
54
62
|
message: request
|
|
55
63
|
)
|
|
56
64
|
resp = @gruf_controller.call(@gruf_controller.request.method_key)
|
|
57
|
-
block.call(resp) if block
|
|
65
|
+
block.call(resp) if block.is_a?(Proc)
|
|
58
66
|
resp
|
|
59
67
|
end
|
|
60
68
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -22,12 +24,14 @@ module Gruf
|
|
|
22
24
|
# Represents configuration settings for the system
|
|
23
25
|
#
|
|
24
26
|
module Configuration
|
|
27
|
+
DEFAULT_RSPEC_PATH = '/spec/rpc/'
|
|
28
|
+
|
|
25
29
|
VALID_CONFIG_KEYS = {
|
|
26
30
|
authentication_hydrators: {
|
|
27
31
|
base: Gruf::Rspec::AuthenticationHydrators::Base,
|
|
28
32
|
basic: Gruf::Rspec::AuthenticationHydrators::Basic
|
|
29
33
|
},
|
|
30
|
-
rpc_spec_path: '
|
|
34
|
+
rpc_spec_path: ENV.fetch('RPC_SPEC_PATH', DEFAULT_RSPEC_PATH).to_s
|
|
31
35
|
}.freeze
|
|
32
36
|
|
|
33
37
|
attr_accessor *VALID_CONFIG_KEYS.keys
|
|
@@ -69,9 +73,9 @@ module Gruf
|
|
|
69
73
|
#
|
|
70
74
|
def reset
|
|
71
75
|
VALID_CONFIG_KEYS.each do |k, v|
|
|
72
|
-
send(
|
|
76
|
+
send("#{k}=", v)
|
|
73
77
|
end
|
|
74
|
-
self.rpc_spec_path = '
|
|
78
|
+
self.rpc_spec_path = ::ENV.fetch('RPC_SPEC_PATH', DEFAULT_RSPEC_PATH).to_s
|
|
75
79
|
options
|
|
76
80
|
end
|
|
77
81
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -110,7 +112,7 @@ module Gruf
|
|
|
110
112
|
# Deserialize the error from the response
|
|
111
113
|
#
|
|
112
114
|
def deserialize_error
|
|
113
|
-
@error_serializer
|
|
115
|
+
@error_serializer&.new(@rpc_response.to_status.metadata[Gruf.error_metadata_key.to_sym])&.deserialize
|
|
114
116
|
end
|
|
115
117
|
end
|
|
116
118
|
end
|
data/lib/gruf/rspec/helpers.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -17,6 +19,9 @@ require_relative 'metadata_factory'
|
|
|
17
19
|
|
|
18
20
|
module Gruf
|
|
19
21
|
module Rspec
|
|
22
|
+
##
|
|
23
|
+
# Module for including rspec helpers
|
|
24
|
+
#
|
|
20
25
|
module Helpers
|
|
21
26
|
##
|
|
22
27
|
# @param [Hash] options
|
data/lib/gruf/rspec/version.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Copyright (c) 2018-present, BigCommerce Pty. Ltd. All rights reserved
|
|
2
4
|
#
|
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
@@ -15,6 +17,6 @@
|
|
|
15
17
|
#
|
|
16
18
|
module Gruf
|
|
17
19
|
module Rspec
|
|
18
|
-
VERSION = '0.
|
|
20
|
+
VERSION = '0.4.0'
|
|
19
21
|
end
|
|
20
22
|
end
|
metadata
CHANGED
|
@@ -1,57 +1,85 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gruf-rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shaun McCormick
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: bundler
|
|
14
|
+
name: bundler-audit
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0.6'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0.6'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: pry
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '0.13'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '0.13'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: rspec_junit_formatter
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
47
|
+
version: '0.4'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
54
|
+
version: '0.4'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rubocop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.82'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.82'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: simplecov
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0.15'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0.15'
|
|
55
83
|
- !ruby/object:Gem::Dependency
|
|
56
84
|
name: gruf
|
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -76,14 +104,14 @@ dependencies:
|
|
|
76
104
|
name: rspec
|
|
77
105
|
requirement: !ruby/object:Gem::Requirement
|
|
78
106
|
requirements:
|
|
79
|
-
- - "
|
|
107
|
+
- - ">="
|
|
80
108
|
- !ruby/object:Gem::Version
|
|
81
109
|
version: '3.8'
|
|
82
110
|
type: :runtime
|
|
83
111
|
prerelease: false
|
|
84
112
|
version_requirements: !ruby/object:Gem::Requirement
|
|
85
113
|
requirements:
|
|
86
|
-
- - "
|
|
114
|
+
- - ">="
|
|
87
115
|
- !ruby/object:Gem::Version
|
|
88
116
|
version: '3.8'
|
|
89
117
|
description: RSpec assistance library for gruf, including testing helpers
|
|
@@ -109,7 +137,7 @@ homepage: https://github.com/bigcommerce/gruf-rspec
|
|
|
109
137
|
licenses:
|
|
110
138
|
- MIT
|
|
111
139
|
metadata: {}
|
|
112
|
-
post_install_message:
|
|
140
|
+
post_install_message:
|
|
113
141
|
rdoc_options: []
|
|
114
142
|
require_paths:
|
|
115
143
|
- lib
|
|
@@ -117,15 +145,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
117
145
|
requirements:
|
|
118
146
|
- - ">="
|
|
119
147
|
- !ruby/object:Gem::Version
|
|
120
|
-
version: '
|
|
148
|
+
version: '2.6'
|
|
121
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
150
|
requirements:
|
|
123
151
|
- - ">="
|
|
124
152
|
- !ruby/object:Gem::Version
|
|
125
153
|
version: '0'
|
|
126
154
|
requirements: []
|
|
127
|
-
rubygems_version: 3.
|
|
128
|
-
signing_key:
|
|
155
|
+
rubygems_version: 3.2.17
|
|
156
|
+
signing_key:
|
|
129
157
|
specification_version: 4
|
|
130
158
|
summary: RSpec assistance library for gruf
|
|
131
159
|
test_files: []
|