grpc_mock 0.3.0 → 0.3.1

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: 64d71ca90aa6a226e3adabaaeb57706fca0c0f64d2a1067ce6e43096325309dd
4
- data.tar.gz: 31d13e31248b47d0fbef1e2b6a684c14e09849b9f122788154701f3df44c4acb
3
+ metadata.gz: d717cdc98c3aa591bd9f3681b243c0fe51a80775d8ff2e3f6a4722c717aa0838
4
+ data.tar.gz: 2843c56fe8383a8d1bb1bacb2c5f64ed3d6f4342ea884052e1bdbf60aa063ba9
5
5
  SHA512:
6
- metadata.gz: 1da4555681fd8e75403c2cad300793c3a7732671258a09ee57426e4cf5b3df5ce68d8d1e8bf5db7ca8122e52997030dbc81de74984f2ff011dc053842de4cd90
7
- data.tar.gz: c40cfd23df2b2106d13e752c882e1dfe809aed80f9bdc41723d632a7b77f9390bf9e20ebd524c7d65857bd5e7bfe527f4cf5eae7c0e04afc92fc28c429a6827b
6
+ metadata.gz: 394cf9c6dfd230e467d10d89933927cbec13273b11c4188358ffacba750dcd8df6eddfd4d546509411962d541c7d99118501d118acdedfbd0004c805d0d94937
7
+ data.tar.gz: d85fd1a0f7f73b94e35d8288648f264bb3c57b63a28d5135d3f9648589fc97d60244255741ea8e5e96b5934b7d2535d82ae49977cbf2db67f7e03ccad753b8d6
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'grpc', '>= 1.12.0', '< 1.21.0'
25
+ spec.add_dependency 'grpc', '>= 1.12.0', '< 1.22.0'
26
26
 
27
27
  spec.add_development_dependency 'bundler'
28
28
  spec.add_development_dependency 'grpc-tools'
@@ -15,7 +15,7 @@ module GrpcMock
15
15
 
16
16
  mock = GrpcMock.stub_registry.response_for_request(method, request)
17
17
  if mock
18
- mock
18
+ mock.evaluate
19
19
  elsif GrpcMock.config.allow_net_connect
20
20
  super
21
21
  else
@@ -32,7 +32,7 @@ module GrpcMock
32
32
  r = requests.to_a # FIXME: this may not work
33
33
  mock = GrpcMock.stub_registry.response_for_request(method, r)
34
34
  if mock
35
- mock
35
+ mock.evaluate
36
36
  elsif GrpcMock.config.allow_net_connect
37
37
  super
38
38
  else
@@ -47,7 +47,7 @@ module GrpcMock
47
47
 
48
48
  mock = GrpcMock.stub_registry.response_for_request(method, request)
49
49
  if mock
50
- mock
50
+ mock.evaluate
51
51
  elsif GrpcMock.config.allow_net_connect
52
52
  super
53
53
  else
@@ -63,7 +63,7 @@ module GrpcMock
63
63
  r = requests.to_a # FIXME: this may not work
64
64
  mock = GrpcMock.stub_registry.response_for_request(method, r)
65
65
  if mock
66
- mock
66
+ mock.evaluate
67
67
  elsif GrpcMock.config.allow_net_connect
68
68
  super
69
69
  else
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'grpc_mock/request_pattern'
4
- require 'grpc_mock/resopnse_sequence'
4
+ require 'grpc_mock/response'
5
+ require 'grpc_mock/response_sequence'
5
6
  require 'grpc_mock/errors'
6
7
 
7
8
  module GrpcMock
@@ -17,8 +18,15 @@ module GrpcMock
17
18
  self
18
19
  end
19
20
 
20
- def to_return(*resp)
21
- @response_sequence << GrpcMock::ResponsesSequence.new(resp)
21
+ def to_return(*values)
22
+ responses = [*values].flatten.map { |v| Response::Value.new(v) }
23
+ @response_sequence << GrpcMock::ResponsesSequence.new(responses)
24
+ self
25
+ end
26
+
27
+ def to_raise(*exceptions)
28
+ responses = [*exceptions].flatten.map { |e| Response::ExceptionValue.new(e) }
29
+ @response_sequence << GrpcMock::ResponsesSequence.new(responses)
22
30
  self
23
31
  end
24
32
 
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GrpcMock
4
+ module Response
5
+ class ExceptionValue
6
+ def initialize(exception)
7
+ @exception = case exception
8
+ when String
9
+ StandardError.new(exception)
10
+ when Class
11
+ exception.new('Exception from GrpcMock')
12
+ when Exception
13
+ exception
14
+ else
15
+ raise ArgumentError.new(message: "Invalid exception class: #{exception.class}")
16
+ end
17
+ end
18
+
19
+ def evaluate
20
+ raise @exception.dup
21
+ end
22
+ end
23
+
24
+ class Value
25
+ def initialize(value)
26
+ @value = value
27
+ end
28
+
29
+ def evaluate
30
+ @value.dup
31
+ end
32
+ end
33
+ end
34
+ end
@@ -24,7 +24,7 @@ module GrpcMock
24
24
  end
25
25
 
26
26
  if rstub
27
- rstub.response.dup
27
+ rstub.response
28
28
  end
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcMock
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
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.3.0
4
+ version: 0.3.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: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2019-06-21 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.21.0
22
+ version: 1.22.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.21.0
32
+ version: 1.22.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,8 @@ files:
142
142
  - lib/grpc_mock/matchers/request_including_matcher.rb
143
143
  - lib/grpc_mock/request_pattern.rb
144
144
  - lib/grpc_mock/request_stub.rb
145
- - lib/grpc_mock/resopnse_sequence.rb
145
+ - lib/grpc_mock/response.rb
146
+ - lib/grpc_mock/response_sequence.rb
146
147
  - lib/grpc_mock/rspec.rb
147
148
  - lib/grpc_mock/stub_registry.rb
148
149
  - lib/grpc_mock/version.rb