gruf-rspec 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fead8ef219ccbfd5f0bbb8f1f33c074d1d3bb9096edff7975689e5f250dd3d5b
4
- data.tar.gz: c2b53d50821bbe478d0de586d8538097dedb286db75c2546b6254cc93598bd6e
3
+ metadata.gz: d5d38dd3004e975f13b70937942bc8ea4abe802f7a6986d19ac83d9769553e03
4
+ data.tar.gz: af9e5b8e3e6e9770f3cc2c2ee118ddfa01588a5b95358860dfaa3917ce8658d6
5
5
  SHA512:
6
- metadata.gz: afd11a9b2f7dc98b1fad45ed7f392c388b9b9200420b23f29fd08e9325d07bfa855eaa996be91e6ed96c63eaf4ff40193cb5026effb36ea498ffaab88a60b280
7
- data.tar.gz: fcac7c62fea2b5b20c533e277410bc222957dfea8a441408ffc36660e3d3c76a83389c01e7edaa7d09f9e79a911019e218a362144c38f0d60901cef9a5b8976f
6
+ metadata.gz: 6787040f316170264bf9c126adba2699e94b32aac4865ed689524b0ae690860c0544bf6ba3f18ac398db5a79c773bb5601d869f1b1162ac94b17f01f3819cfe2
7
+ data.tar.gz: 0ca44f374317fe24ccfa4344910623a7b3601cf85e0a5e1b4ce376116215e8dcf5dd9d4cf2d31cf4cc02ee410f39c92dc7a5e58bb52d1a5be2313314e2ecf8ae
@@ -2,6 +2,32 @@ Changelog for the gruf-rspec gem.
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 0.3.0
6
+
7
+ - [#7] Fix issue where RPC_SPEC_PATH defaulting is hardcoded
8
+ - Drop support for Ruby < 2.6, add 2.7 tests
9
+ - Update rubocop to 1.0
10
+
11
+ ### 0.2.2
12
+
13
+ * Loosen rspec dependency
14
+
15
+ ### 0.2.1
16
+
17
+ * Loosen rack dependency
18
+
19
+ ### 0.2.0
20
+
21
+ * Deprecate support for Ruby < 2.4
22
+
23
+ ### 0.1.3
24
+
25
+ * Add ability to include metadata in rpc calls
26
+
27
+ ### 0.1.2
28
+
29
+ * Fix issue with RSPEC_NAMESPACE conflicts with other gems
30
+
5
31
  ### 0.1.1
6
32
 
7
33
  * Add be_a_successful_rpc matcher that matches on success and the appropriate response class
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # gruf-rspec
2
2
 
3
- [![Build Status](https://travis-ci.com/bigcommerce/gruf-rspec.svg?token=D3Cc4LCF9BgpUx4dpPpv&branch=master)](https://travis-ci.com/bigcommerce/gruf-rspec) [![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=master)](https://inch-ci.org/github/bigcommerce/gruf-rspec?branch=master)
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)
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+ and RSpec 3.8+.
20
+ Note that this gem requires at least Ruby 2.4+, 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 two args: The gRPC method name, and the request object
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
- subject { run_rpc(:GetThing, request_proto) }
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
@@ -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('../lib', __FILE__)
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,23 @@ Gem::Specification.new do |spec|
24
26
  spec.email = ['splittingred@gmail.com']
25
27
  spec.license = 'MIT'
26
28
 
27
- spec.summary = %q{RSpec assistance library for gruf}
28
- spec.description = %q{RSpec assistance library for gruf, including testing helpers}
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
- # Specify which files should be added to the gem when it is released.
32
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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', '~> 1.16'
37
- spec.add_development_dependency 'rake', '~> 10.0'
38
- spec.add_development_dependency 'pry'
38
+ spec.add_development_dependency 'bundler', '~> 1.11'
39
+ spec.add_development_dependency 'bundler-audit', '~> 0.6'
40
+ spec.add_development_dependency 'pry', '>= 0.13'
41
+ spec.add_development_dependency 'rspec', '~> 3.8'
42
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
43
+ spec.add_development_dependency 'rubocop', '~> 0.82'
44
+ spec.add_development_dependency 'simplecov', '~> 0.15'
39
45
 
40
46
  spec.add_dependency 'gruf', '~> 2.5', '>= 2.5.1'
41
- spec.add_dependency 'rspec', '~> 3.8'
47
+ spec.add_dependency 'rspec', '>= 3.8'
42
48
  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
@@ -16,12 +18,12 @@
16
18
  begin
17
19
  require 'rspec/core'
18
20
  require 'rspec/expectations'
19
- RSPEC_NAMESPACE = RSpec
20
- RSPEC_RUNNER = RSpec
21
+ GRUF_RSPEC_NAMESPACE = RSpec
22
+ GRUF_RSPEC_RUNNER = RSpec
21
23
  rescue LoadError # old rspec compat
22
24
  require 'spec'
23
- RSPEC_NAMESPACE = Spec
24
- RSPEC_RUNNER = Spec::Runner
25
+ GRUF_RSPEC_NAMESPACE = Spec
26
+ GRUF_RSPEC_RUNNER = Spec::Runner
25
27
  end
26
28
 
27
29
  require_relative 'rspec/version'
@@ -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
@@ -37,7 +45,7 @@ end
37
45
 
38
46
  Gruf::Rspec.reset # initial reset
39
47
 
40
- RSPEC_RUNNER.configure do |config|
48
+ GRUF_RSPEC_RUNNER.configure do |config|
41
49
  config.include Gruf::Rspec::Helpers
42
50
 
43
51
  config.define_derived_metadata(file_path: Regexp.new(Gruf::Rspec.rpc_spec_path)) do |metadata|
@@ -45,16 +53,16 @@ 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 && block.is_a?(Proc)
65
+ block.call(resp) if block.is_a?(Proc)
58
66
  resp
59
67
  end
60
68
 
@@ -68,7 +76,7 @@ RSPEC_RUNNER.configure do |config|
68
76
  end
69
77
  end
70
78
 
71
- RSPEC_NAMESPACE::Matchers.define :raise_rpc_error do |expected_error_class|
79
+ GRUF_RSPEC_NAMESPACE::Matchers.define :raise_rpc_error do |expected_error_class|
72
80
  supports_block_expectations
73
81
 
74
82
  def with_serialized(&block)
@@ -90,7 +98,7 @@ RSPEC_NAMESPACE::Matchers.define :raise_rpc_error do |expected_error_class|
90
98
  end
91
99
  end
92
100
 
93
- RSPEC_NAMESPACE::Matchers.define :be_a_successful_rpc do |_|
101
+ GRUF_RSPEC_NAMESPACE::Matchers.define :be_a_successful_rpc do |_|
94
102
  match do |actual|
95
103
  if !gruf_controller || actual.is_a?(GRPC::BadStatus) || actual.is_a?(GRPC::Core::CallError)
96
104
  false
@@ -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
@@ -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
@@ -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: '/spec/rpc/'.freeze
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((k.to_s + '='), v)
76
+ send("#{k}=", v)
73
77
  end
74
- self.rpc_spec_path = '/spec/rpc/'.freeze
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.new(@rpc_response.to_status.metadata[Gruf.error_metadata_key.to_sym]).deserialize if @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
@@ -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
@@ -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
@@ -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.1.1'.freeze
20
+ VERSION = '0.3.0'
19
21
  end
20
22
  end
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.1.1
4
+ version: 0.3.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: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '1.11'
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: '1.16'
26
+ version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler-audit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0.6'
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: '10.0'
40
+ version: '0.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.13'
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.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.82'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.82'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.15'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.15'
55
111
  - !ruby/object:Gem::Dependency
56
112
  name: gruf
57
113
  requirement: !ruby/object:Gem::Requirement
@@ -76,14 +132,14 @@ dependencies:
76
132
  name: rspec
77
133
  requirement: !ruby/object:Gem::Requirement
78
134
  requirements:
79
- - - "~>"
135
+ - - ">="
80
136
  - !ruby/object:Gem::Version
81
137
  version: '3.8'
82
138
  type: :runtime
83
139
  prerelease: false
84
140
  version_requirements: !ruby/object:Gem::Requirement
85
141
  requirements:
86
- - - "~>"
142
+ - - ">="
87
143
  - !ruby/object:Gem::Version
88
144
  version: '3.8'
89
145
  description: RSpec assistance library for gruf, including testing helpers
@@ -109,7 +165,7 @@ homepage: https://github.com/bigcommerce/gruf-rspec
109
165
  licenses:
110
166
  - MIT
111
167
  metadata: {}
112
- post_install_message:
168
+ post_install_message:
113
169
  rdoc_options: []
114
170
  require_paths:
115
171
  - lib
@@ -117,16 +173,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
173
  requirements:
118
174
  - - ">="
119
175
  - !ruby/object:Gem::Version
120
- version: '0'
176
+ version: '2.6'
121
177
  required_rubygems_version: !ruby/object:Gem::Requirement
122
178
  requirements:
123
179
  - - ">="
124
180
  - !ruby/object:Gem::Version
125
181
  version: '0'
126
182
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.7
129
- signing_key:
183
+ rubygems_version: 3.0.9
184
+ signing_key:
130
185
  specification_version: 4
131
186
  summary: RSpec assistance library for gruf
132
187
  test_files: []