grpc_mock 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +89 -0
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +39 -11
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/grpc_mock.gemspec +4 -2
- data/lib/grpc_mock.rb +10 -4
- data/lib/grpc_mock/adapter.rb +2 -0
- data/lib/grpc_mock/api.rb +26 -0
- data/lib/grpc_mock/configuration.rb +2 -0
- data/lib/grpc_mock/errors.rb +8 -0
- data/lib/grpc_mock/grpc_stub_adapter.rb +25 -8
- data/lib/grpc_mock/matchers/hash_argument_matcher.rb +43 -0
- data/lib/grpc_mock/matchers/request_including_matcher.rb +39 -0
- data/lib/grpc_mock/request_pattern.rb +25 -0
- data/lib/grpc_mock/request_stub.rb +46 -0
- data/lib/grpc_mock/resopnse_sequence.rb +39 -0
- data/lib/grpc_mock/rspec.rb +6 -0
- data/lib/grpc_mock/stub_registry.rb +31 -0
- data/lib/grpc_mock/version.rb +3 -1
- metadata +14 -7
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dab269f850e0b8b76e59bf38cda65711c45777e9
|
4
|
+
data.tar.gz: b4940189dfaf12d0709fe82bc8f35683b2d6f079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9306c34913f4f82cad53287296c5d41add574e83976afb2292095f755146638cc100bb9256ea51ac514e1b98c26de7fb8c93d7c4b8c6070bb8dae6e2634b20ff
|
7
|
+
data.tar.gz: 10113af184c522fc9cf9f29dd4198726a6eec7198d7b0182a0a156b7fd5819cb06f8991cf3bff0807a3f8bc950f822c0f52492a5882b7221ce533301cd6b8982
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,92 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- 'spec/examples/**/*'
|
4
|
+
- '**/**/*_pb.rb' # auto-generated
|
5
|
+
DisplayCopNames: true
|
6
|
+
TargetRubyVersion: 2.5
|
7
|
+
|
8
|
+
Style/AndOr:
|
9
|
+
EnforcedStyle: conditionals
|
10
|
+
|
11
|
+
Style/AsciiComments:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/DoubleNegation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/EmptyElse:
|
21
|
+
EnforcedStyle: empty
|
22
|
+
|
23
|
+
Style/FormatString:
|
24
|
+
EnforcedStyle: percent
|
25
|
+
|
26
|
+
Style/IfUnlessModifier:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/TrailingCommaInHashLiteral:
|
30
|
+
EnforcedStyleForMultiline: comma
|
31
|
+
|
32
|
+
Style/TrailingCommaInArrayLiteral:
|
33
|
+
EnforcedStyleForMultiline: comma
|
34
|
+
|
35
|
+
Style/TrailingCommaInArguments:
|
36
|
+
EnforcedStyleForMultiline: comma
|
37
|
+
|
38
|
+
Style/SafeNavigation:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/WhileUntilModifier:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Naming/PredicateName:
|
45
|
+
NamePrefixBlacklist:
|
46
|
+
- "is_"
|
47
|
+
- "have_"
|
48
|
+
NamePrefix:
|
49
|
+
- "is_"
|
50
|
+
- "have_"
|
51
|
+
|
52
|
+
Style/SignalException:
|
53
|
+
EnforcedStyle: only_raise
|
54
|
+
|
55
|
+
Style/SingleLineBlockParams:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/NumericLiterals:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/GuardClause:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/NumericPredicate:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Metrics/ParameterLists:
|
68
|
+
CountKeywordArgs: false
|
69
|
+
|
70
|
+
Lint/UnderscorePrefixedVariableName:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Metrics/AbcSize:
|
74
|
+
Max: 50
|
75
|
+
|
76
|
+
Metrics/CyclomaticComplexity:
|
77
|
+
Max: 10
|
78
|
+
|
79
|
+
Metrics/LineLength:
|
80
|
+
Max: 160
|
81
|
+
|
82
|
+
Metrics/MethodLength:
|
83
|
+
Max: 40
|
84
|
+
|
85
|
+
Metrics/PerceivedComplexity:
|
86
|
+
Max: 20
|
87
|
+
|
88
|
+
Metrics/ClassLength:
|
89
|
+
Max: 200
|
90
|
+
|
91
|
+
Metrics/BlockLength:
|
92
|
+
Max: 40
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# GrpcMock [![Build Status](https://travis-ci.org/ganmacs/grpc_mock.svg?branch=master)](https://travis-ci.org/ganmacs/grpc_mock)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Library for stubbing grpc in Ruby.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,22 +20,52 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
If you use [RSpec](https://github.com/rspec/rspec), add the following code to spec/spec_helper.rb:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'grpc_mock/rspec'
|
27
|
+
```
|
28
|
+
|
29
|
+
## Examples
|
30
|
+
|
31
|
+
See definition of protocol buffers and gRPC generated code in [spec/exmaples/hello](https://github.com/ganmacs/grpc_mock/tree/master/spec/examples/hello)
|
32
|
+
|
33
|
+
##### Stubbed request based on path and with the default response
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
GrpcMock.stub_request("/hello.hello/Hello").to_return(Hello::HelloResponse.new(msg: 'test'))
|
37
|
+
|
38
|
+
client = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)
|
39
|
+
client = client.hello(Hello::HelloRequest.new(msg: 'hi')) # => Hello::HelloResponse.new(msg: 'test')
|
40
|
+
```
|
41
|
+
|
42
|
+
##### Stubbing requests based on path and request
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
GrpcMock.stub_request("/hello.hello/Hello").with(Hello::HelloRequest.new(msg: 'hi')).to_return(Hello::HelloResponse.new(msg: 'test'))
|
46
|
+
|
47
|
+
client = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)
|
48
|
+
client = client.hello(Hello::HelloRequest.new(msg: 'hello')) # => send a request to server
|
49
|
+
client = client.hello(Hello::HelloRequest.new(msg: 'hi')) # => Hello::HelloResponse.new(msg: 'test') (without any requests to server)
|
50
|
+
```
|
26
51
|
|
27
|
-
|
52
|
+
##### Real requests to network can be allowed or disabled
|
28
53
|
|
29
|
-
|
54
|
+
```ruby
|
55
|
+
client = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure)
|
30
56
|
|
31
|
-
|
57
|
+
GrpcMock.disable_net_connect!
|
58
|
+
client = client.hello(Hello::HelloRequest.new(msg: 'hello')) # => Raise NetConnectNotAllowedError error
|
59
|
+
|
60
|
+
GrpcMock.allow_net_connect!
|
61
|
+
client = Hello::Hello::Stub.new('localhost:8000', :this_channel_is_insecure) # => send a request to server
|
62
|
+
```
|
32
63
|
|
33
64
|
## Contributing
|
34
65
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/grpc_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
67
|
|
37
68
|
## License
|
38
69
|
|
39
70
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
71
|
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the GrpcMock project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grpc_mock/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/grpc_mock.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'grpc_mock/version'
|
@@ -5,7 +7,7 @@ require 'grpc_mock/version'
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
8
|
spec.name = 'grpc_mock'
|
7
9
|
spec.version = GrpcMock::VERSION
|
8
|
-
spec.authors = ['
|
10
|
+
spec.authors = ['Yuta Iwama']
|
9
11
|
spec.email = ['ganmacs@gmail.com']
|
10
12
|
|
11
13
|
spec.summary = 'Library for stubbing grpc in Ruby'
|
@@ -20,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
20
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
23
|
spec.require_paths = ['lib']
|
22
24
|
|
23
|
-
spec.add_dependency 'grpc', '>= 1.12.0', '< 1.
|
25
|
+
spec.add_dependency 'grpc', '>= 1.12.0', '< 1.18.0'
|
24
26
|
|
25
27
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
28
|
spec.add_development_dependency 'grpc-tools'
|
data/lib/grpc_mock.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_mock/api'
|
1
4
|
require 'grpc_mock/version'
|
2
5
|
require 'grpc_mock/configuration'
|
3
6
|
require 'grpc_mock/adapter'
|
7
|
+
require 'grpc_mock/stub_registry'
|
4
8
|
|
5
9
|
module GrpcMock
|
10
|
+
extend GrpcMock::Api
|
11
|
+
|
6
12
|
class << self
|
7
13
|
def enable!
|
8
14
|
adapter.enable!
|
@@ -12,12 +18,12 @@ module GrpcMock
|
|
12
18
|
adapter.disable!
|
13
19
|
end
|
14
20
|
|
15
|
-
def
|
16
|
-
|
21
|
+
def reset!
|
22
|
+
GrpcMock.stub_registry.reset!
|
17
23
|
end
|
18
24
|
|
19
|
-
def
|
20
|
-
|
25
|
+
def stub_registry
|
26
|
+
@stub_registry ||= GrpcMock::StubRegistry.new
|
21
27
|
end
|
22
28
|
|
23
29
|
def adapter
|
data/lib/grpc_mock/adapter.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_mock/request_stub'
|
4
|
+
require 'grpc_mock/matchers/request_including_matcher'
|
5
|
+
|
6
|
+
module GrpcMock
|
7
|
+
module Api
|
8
|
+
# @param path [String]
|
9
|
+
def stub_request(path)
|
10
|
+
GrpcMock.stub_registry.register_request_stub(GrpcMock::RequestStub.new(path))
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param values [Hash]
|
14
|
+
def request_including(values)
|
15
|
+
GrpcMock::Matchers::RequestIncludingMatcher.new(values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def disable_net_connect!
|
19
|
+
GrpcMock.config.allow_net_connect = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def allow_net_connect!
|
23
|
+
GrpcMock.config.allow_net_connect = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/grpc_mock/errors.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GrpcMock
|
2
4
|
class NetConnectNotAllowedError < StandardError
|
3
5
|
def initialize(sigunature)
|
4
6
|
super("Real GRPC connections are disabled. #{sigunature} is requested")
|
5
7
|
end
|
6
8
|
end
|
9
|
+
|
10
|
+
class NoResponseError < StandardError
|
11
|
+
def initialize(msg)
|
12
|
+
super("There is no response: #{msg}")
|
13
|
+
end
|
14
|
+
end
|
7
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'grpc'
|
2
4
|
require 'grpc_mock/errors'
|
3
5
|
|
@@ -6,48 +8,63 @@ module GrpcMock
|
|
6
8
|
# To make hook point for GRPC::ClientStub
|
7
9
|
# https://github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
|
8
10
|
class AdapterClass < GRPC::ClientStub
|
9
|
-
def request_response(method, *args)
|
11
|
+
def request_response(method, request, *args)
|
10
12
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
11
13
|
return super
|
12
14
|
end
|
13
15
|
|
14
|
-
|
16
|
+
mock = GrpcMock.stub_registry.response_for_request(method, request)
|
17
|
+
if mock
|
18
|
+
mock
|
19
|
+
elsif GrpcMock.config.allow_net_connect
|
15
20
|
super
|
16
21
|
else
|
17
22
|
raise NetConnectNotAllowedError, method
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
|
26
|
+
# TODO
|
27
|
+
def client_streamer(method, requests, *args)
|
22
28
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
23
29
|
return super
|
24
30
|
end
|
25
31
|
|
26
|
-
|
32
|
+
r = requests.to_a # FIXME: this may not work
|
33
|
+
mock = GrpcMock.stub_registry.response_for_request(method, r)
|
34
|
+
if mock
|
35
|
+
mock
|
36
|
+
elsif GrpcMock.config.allow_net_connect
|
27
37
|
super
|
28
38
|
else
|
29
39
|
raise NetConnectNotAllowedError, method
|
30
40
|
end
|
31
41
|
end
|
32
42
|
|
33
|
-
def server_streamer(method, *args)
|
43
|
+
def server_streamer(method, request, *args)
|
34
44
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
35
45
|
return super
|
36
46
|
end
|
37
47
|
|
38
|
-
|
48
|
+
mock = GrpcMock.stub_registry.response_for_request(method, request)
|
49
|
+
if mock
|
50
|
+
mock
|
51
|
+
elsif GrpcMock.config.allow_net_connect
|
39
52
|
super
|
40
53
|
else
|
41
54
|
raise NetConnectNotAllowedError, method
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
45
|
-
def bidi_streamer(method, *args)
|
58
|
+
def bidi_streamer(method, requests, *args)
|
46
59
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
47
60
|
return super
|
48
61
|
end
|
49
62
|
|
50
|
-
|
63
|
+
r = requests.to_a # FIXME: this may not work
|
64
|
+
mock = GrpcMock.stub_registry.response_for_request(method, r)
|
65
|
+
if mock
|
66
|
+
mock
|
67
|
+
elsif GrpcMock.config.allow_net_connect
|
51
68
|
super
|
52
69
|
else
|
53
70
|
raise NetConnectNotAllowedError, method
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrpcMock
|
4
|
+
module Matchers
|
5
|
+
# Base class for Hash matchers
|
6
|
+
# https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
|
7
|
+
class HashArgumentMatcher
|
8
|
+
def self.stringify_keys!(arg, options = {})
|
9
|
+
case arg
|
10
|
+
when Array
|
11
|
+
arg.map do |elem|
|
12
|
+
options[:deep] ? stringify_keys!(elem, options) : elem
|
13
|
+
end
|
14
|
+
when Hash
|
15
|
+
Hash[
|
16
|
+
*arg.map do |key, value|
|
17
|
+
k = key.is_a?(Symbol) ? key.to_s : key
|
18
|
+
v = (options[:deep] ? stringify_keys!(value, options) : value)
|
19
|
+
[k, v]
|
20
|
+
end.inject([]) { |r, x| r + x }]
|
21
|
+
else
|
22
|
+
arg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(expected)
|
27
|
+
@expected = Hash[
|
28
|
+
GrpcMock::Matchers::HashArgumentMatcher.stringify_keys!(expected, deep: true).sort,
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(_actual, &block)
|
33
|
+
@expected.all?(&block)
|
34
|
+
rescue NoMethodError
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.from_rspec_matcher(matcher)
|
39
|
+
new(matcher.instance_variable_get(:@expected))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_mock/matchers/hash_argument_matcher'
|
4
|
+
|
5
|
+
module GrpcMock
|
6
|
+
module Matchers
|
7
|
+
class RequestIncludingMatcher < HashArgumentMatcher
|
8
|
+
def ==(actual)
|
9
|
+
if actual.respond_to?(:to_h)
|
10
|
+
actual = actual.to_h
|
11
|
+
end
|
12
|
+
|
13
|
+
actual = Hash[GrpcMock::Matchers::HashArgumentMatcher.stringify_keys!(actual, deep: true)]
|
14
|
+
super { |key, value| inner_including(value, key, actual) }
|
15
|
+
rescue NoMethodError
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def inner_including(expect, key, actual)
|
22
|
+
if actual.key?(key)
|
23
|
+
actual_value = actual[key]
|
24
|
+
if expect.is_a?(Hash)
|
25
|
+
RequestIncludingMatcher.new(expect) == actual_value
|
26
|
+
else
|
27
|
+
expect === actual_value
|
28
|
+
end
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
"reqeust_including(#{@expected.inspect})"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrpcMock
|
4
|
+
class RequestPattern
|
5
|
+
# @param path [String]
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
@block = nil
|
9
|
+
@request = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def with(request = nil, &block)
|
13
|
+
if request.nil? && !block_given?
|
14
|
+
raise ArgumentError, '#with method invoked with no arguments. Either options request or block must be specified.'
|
15
|
+
end
|
16
|
+
|
17
|
+
@request = request
|
18
|
+
@block = block
|
19
|
+
end
|
20
|
+
|
21
|
+
def match?(path, request)
|
22
|
+
@path == path && (@request.nil? || @request == request) && (@block.nil? || @block.call(path))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'grpc_mock/request_pattern'
|
4
|
+
require 'grpc_mock/resopnse_sequence'
|
5
|
+
require 'grpc_mock/errors'
|
6
|
+
|
7
|
+
module GrpcMock
|
8
|
+
class RequestStub
|
9
|
+
# @param path [String] gRPC path like /${service_name}/${method_name}
|
10
|
+
def initialize(path)
|
11
|
+
@request_pattern = RequestPattern.new(path)
|
12
|
+
@response_sequence = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def with(request = nil, &block)
|
16
|
+
@request_pattern.with(request, &block)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_return(*resp)
|
21
|
+
@response_sequence << GrpcMock::ResponsesSequence.new(resp)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def response
|
26
|
+
if @response_sequence.empty?
|
27
|
+
raise GrpcMock::NoResponseError, 'Must be set some values by using #GrpMock::RequestStub#to_run'
|
28
|
+
elsif @response_sequence.size == 1
|
29
|
+
@response_sequence.first.next
|
30
|
+
else
|
31
|
+
if @response_sequence.first.end?
|
32
|
+
@response_sequence.shift
|
33
|
+
end
|
34
|
+
|
35
|
+
@response_sequence.first.next
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param path [String]
|
40
|
+
# @param request [Object]
|
41
|
+
# @return [Bool]
|
42
|
+
def match?(path, request)
|
43
|
+
@request_pattern.match?(path, request)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrpcMock
|
4
|
+
class ResponsesSequence
|
5
|
+
attr_accessor :repeat
|
6
|
+
|
7
|
+
def initialize(responses)
|
8
|
+
@repeat = 1
|
9
|
+
@responses = responses
|
10
|
+
@current = 0
|
11
|
+
@last = @responses.length - 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def end?
|
15
|
+
@repeat == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def next
|
19
|
+
if @repeat > 0
|
20
|
+
response = @responses[@current]
|
21
|
+
next_pos
|
22
|
+
response
|
23
|
+
else
|
24
|
+
@responses.last
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def next_pos
|
31
|
+
if @last == @current
|
32
|
+
@current = 0
|
33
|
+
@repeat -= 1
|
34
|
+
else
|
35
|
+
@current += 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/grpc_mock/rspec.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrpcMock
|
4
|
+
class StubRegistry
|
5
|
+
def initialize
|
6
|
+
@request_stubs = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset!
|
10
|
+
@request_stubs = []
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param stub [GrpcMock::RequestStub]
|
14
|
+
def register_request_stub(stub)
|
15
|
+
@request_stubs.unshift(stub)
|
16
|
+
stub
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param path [String]
|
20
|
+
# @param request [Object]
|
21
|
+
def response_for_request(path, request)
|
22
|
+
rstub = @request_stubs.find do |stub|
|
23
|
+
stub.match?(path, request)
|
24
|
+
end
|
25
|
+
|
26
|
+
if rstub
|
27
|
+
rstub.response.dup
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/grpc_mock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Yuta Iwama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 1.12.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.18.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 1.12.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.18.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,8 +124,8 @@ files:
|
|
124
124
|
- ".gitignore"
|
125
125
|
- ".rspec"
|
126
126
|
- ".rubocop.yml"
|
127
|
+
- ".ruby-version"
|
127
128
|
- ".travis.yml"
|
128
|
-
- CODE_OF_CONDUCT.md
|
129
129
|
- Gemfile
|
130
130
|
- LICENSE.txt
|
131
131
|
- README.md
|
@@ -135,10 +135,17 @@ files:
|
|
135
135
|
- grpc_mock.gemspec
|
136
136
|
- lib/grpc_mock.rb
|
137
137
|
- lib/grpc_mock/adapter.rb
|
138
|
+
- lib/grpc_mock/api.rb
|
138
139
|
- lib/grpc_mock/configuration.rb
|
139
140
|
- lib/grpc_mock/errors.rb
|
140
141
|
- lib/grpc_mock/grpc_stub_adapter.rb
|
142
|
+
- lib/grpc_mock/matchers/hash_argument_matcher.rb
|
143
|
+
- lib/grpc_mock/matchers/request_including_matcher.rb
|
144
|
+
- lib/grpc_mock/request_pattern.rb
|
145
|
+
- lib/grpc_mock/request_stub.rb
|
146
|
+
- lib/grpc_mock/resopnse_sequence.rb
|
141
147
|
- lib/grpc_mock/rspec.rb
|
148
|
+
- lib/grpc_mock/stub_registry.rb
|
142
149
|
- lib/grpc_mock/version.rb
|
143
150
|
homepage: https://github.com/ganmacs/grpc_mock
|
144
151
|
licenses:
|
@@ -160,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
167
|
version: '0'
|
161
168
|
requirements: []
|
162
169
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.6.14
|
170
|
+
rubygems_version: 2.6.14.3
|
164
171
|
signing_key:
|
165
172
|
specification_version: 4
|
166
173
|
summary: Library for stubbing grpc in Ruby
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at TODO: Write your email address. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|