protobuf-rspec 0.2.3 → 1.0.0.rc1
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 +7 -0
- data/README.md +29 -1
- data/lib/protobuf/rspec/helpers.rb +90 -13
- data/lib/protobuf/rspec/version.rb +1 -1
- data/protobuf-rspec.gemspec +3 -3
- metadata +43 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75f4085dce2b39870d9c0e727802b1fa9b932092
|
4
|
+
data.tar.gz: c1e8fd5a05bbbb5247d1317c2d0c83cd18505ca2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ddfb37df0a592dd5d384abfea2b2e479233d8ba960d16ea30c01bd6ef4b1aebb8db0bd349fe43083747ee600353928355574b73628b0ee3325940f769d56929
|
7
|
+
data.tar.gz: 452459206a10534d3d048cadd194677e1933fac119a9beb397a740f48a2cd177a4354f8514e74644ecba64261ec0b57df35318ac8ddf0a03926d18814ea719c4
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Unit-Testing Service Behavior
|
|
20
20
|
|
21
21
|
### `local_rpc`
|
22
22
|
|
23
|
-
To unit test your service you should use the `local_rpc` helper method. `local_rpc` helps you call the service instance method of your choosing to ensure that the correct responses are generated with the given requests. This should be used to outside-in test a local RPC Service without testing the underlying socket implementation or needing actual client code to invoke the endpoint method under test.
|
23
|
+
To unit test your service you should use the `local_rpc` helper method. `local_rpc` helps you call the service instance method of your choosing to ensure that the correct responses are generated with the given requests. This should be used to outside-in test a local RPC Service without testing the underlying socket implementation or needing actual client code to invoke the endpoint method under test. Any filters added to the service **will** be invoked.
|
24
24
|
|
25
25
|
Given the service implementation below:
|
26
26
|
|
@@ -88,6 +88,34 @@ describe Services::UserService do
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
+
### `rpc`
|
92
|
+
|
93
|
+
Make an RPC call (without testing the underlying socket implementation). Works the same as `local_rpc`, but invokes the entire RPC middleware stack (service filters are also run):
|
94
|
+
|
95
|
+
```Ruby
|
96
|
+
rpc(:create, user_request) # => UserService#create
|
97
|
+
```
|
98
|
+
|
99
|
+
### `rpc_env`
|
100
|
+
|
101
|
+
Initialize a new RPC env object simulating what happens in the middleware stack.
|
102
|
+
Useful for testing a service class directly without using `rpc` or `local_rpc`.
|
103
|
+
|
104
|
+
```Ruby
|
105
|
+
describe "#create" do
|
106
|
+
# Initialize request and response
|
107
|
+
# ...
|
108
|
+
let(:env) { rpc_env(:create, request) }
|
109
|
+
|
110
|
+
subject { described_class.new(env) }
|
111
|
+
|
112
|
+
it "creates a user" do
|
113
|
+
subject.create
|
114
|
+
subject.response.should eq response
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
91
119
|
### `subject_service`
|
92
120
|
|
93
121
|
One thing to note is that `local_rpc` uses `described_class` as the class to invoke for the given method. If you need to instead test a different class than your `described_class`, simply pass a block to `subject_service` which returns the class you would like to use instead.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'protobuf/rpc/
|
1
|
+
require 'protobuf/rpc/server'
|
2
2
|
|
3
3
|
# RSpec Helpers designed to give you mock abstraction of client or service layer.
|
4
4
|
# Require as protobuf/rspec/helpers and include into your running RSpec configuration.
|
@@ -8,6 +8,7 @@ require 'protobuf/rpc/rpc.pb'
|
|
8
8
|
# RSpec.configure do |config|
|
9
9
|
# config.include Protobuf::Rspec::Helpers
|
10
10
|
# end
|
11
|
+
#
|
11
12
|
module Protobuf
|
12
13
|
module RSpec
|
13
14
|
module Helpers
|
@@ -34,7 +35,6 @@ module Protobuf
|
|
34
35
|
# its('response.records') { should have(3).items }
|
35
36
|
# end
|
36
37
|
#
|
37
|
-
#
|
38
38
|
def subject_service
|
39
39
|
if block_given?
|
40
40
|
@_subject_service = yield
|
@@ -51,8 +51,8 @@ module Protobuf
|
|
51
51
|
self.class.subject_service
|
52
52
|
end
|
53
53
|
|
54
|
-
# Call a local service to test responses and behavior based on the
|
55
|
-
#
|
54
|
+
# Call a local RPC service to test responses and behavior based on the
|
55
|
+
# given request (without testing the underlying socket implementation).
|
56
56
|
#
|
57
57
|
# @example Test a local service method
|
58
58
|
# # Implementation
|
@@ -118,22 +118,80 @@ module Protobuf
|
|
118
118
|
# @param [Symbol, String] method a symbol or string denoting the method to call.
|
119
119
|
# @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
|
120
120
|
# @return [Protobuf::Message or String] the resulting protobuf message or error string
|
121
|
+
#
|
121
122
|
def local_rpc(rpc_method, request)
|
122
|
-
|
123
|
-
|
123
|
+
env = rpc_env(rpc_method, request)
|
124
|
+
service = subject_service.new(env)
|
124
125
|
|
125
|
-
|
126
|
-
:method_name => rpc_method.to_s,
|
127
|
-
:request_proto => request.serialize_to_string }
|
126
|
+
yield(service) if block_given?
|
128
127
|
|
129
|
-
|
130
|
-
|
128
|
+
# Dispatch the RPC method invoking all of the filters
|
129
|
+
service.callable_rpc_method(rpc_method).call
|
130
|
+
service.response
|
131
|
+
end
|
131
132
|
|
132
|
-
|
133
|
+
# Make an RPC call invoking the entire middleware stack (without testing
|
134
|
+
# the underlying socket implementation). Works the same as `local_rpc`, but
|
135
|
+
# invokes the entire RPC middleware stack.
|
136
|
+
#
|
137
|
+
# @example Test an RPC method
|
138
|
+
#
|
139
|
+
# it "returns a user" do
|
140
|
+
# response = rpc(:find, request)
|
141
|
+
# response.should eq user
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# @param [Symbol, String] method a symbol or string denoting the method to call.
|
145
|
+
# @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
|
146
|
+
# @return [Protobuf::Message or Protobuf::Rpc::PbError] the resulting Protobuf message or RPC error.
|
147
|
+
#
|
148
|
+
def rpc(rpc_method, request)
|
149
|
+
request_wrapper = wrapped_request(rpc_method, request)
|
133
150
|
|
134
|
-
|
151
|
+
env = ::Protobuf::Rpc::Env.new('encoded_request' => request_wrapper.encode)
|
152
|
+
env = ::Protobuf::Rpc.middleware.call(env)
|
153
|
+
|
154
|
+
env.response
|
135
155
|
end
|
136
156
|
|
157
|
+
# Initialize a new RPC env object simulating what happens in the middleware stack.
|
158
|
+
# Useful for testing a service class directly without using `rpc` or `local_rpc`.
|
159
|
+
#
|
160
|
+
# @example Test an RPC method on the service directly
|
161
|
+
#
|
162
|
+
# describe "#create" do
|
163
|
+
# # Initialize request and response
|
164
|
+
# # ...
|
165
|
+
# let(:env) { rpc_env(:create, request) }
|
166
|
+
#
|
167
|
+
# subject { described_class.new(env) }
|
168
|
+
#
|
169
|
+
# it "creates a user" do
|
170
|
+
# subject.create
|
171
|
+
# subject.response.should eq response
|
172
|
+
# end
|
173
|
+
# end
|
174
|
+
#
|
175
|
+
# @param [Symbol, String] method a symbol or string denoting the method to call.
|
176
|
+
# @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
|
177
|
+
# @return [Protobuf::Rpc::Env] the environment derived from an RPC request.
|
178
|
+
#
|
179
|
+
def rpc_env(rpc_method, request)
|
180
|
+
request = request_class(rpc_method).new(request) if request.is_a?(Hash)
|
181
|
+
|
182
|
+
::Protobuf::Rpc::Env.new(
|
183
|
+
'caller' => 'protobuf-rspec',
|
184
|
+
'service_name' => subject_service.to_s,
|
185
|
+
'method_name' => rpc_method.to_s,
|
186
|
+
'request' => request,
|
187
|
+
'request_type' => request_class(rpc_method),
|
188
|
+
'response_type' => response_class(rpc_method),
|
189
|
+
'rpc_method' => subject_service.rpcs[rpc_method],
|
190
|
+
'rpc_service' => subject_service
|
191
|
+
)
|
192
|
+
end
|
193
|
+
alias_method :env_for_request, :rpc_env
|
194
|
+
|
137
195
|
# Create a mock service that responds in the way you are expecting to aid in testing client -> service calls.
|
138
196
|
# In order to test your success callback you should provide a :response object. Similarly, to test your failure
|
139
197
|
# callback you should provide an :error object.
|
@@ -228,6 +286,7 @@ module Protobuf
|
|
228
286
|
# @param [Hash] callbacks provides expectation objects to invoke on_success (with :response), on_failure (with :error), and the request object (:request)
|
229
287
|
# @param [Block] optional. When given, will be invoked with the request message sent to the client method
|
230
288
|
# @return [Mock] the stubbed out client mock
|
289
|
+
#
|
231
290
|
def mock_rpc(klass, method, callbacks = {})
|
232
291
|
client = double('Client', :on_success => true, :on_failure => true)
|
233
292
|
client.stub(method).and_yield(client)
|
@@ -275,6 +334,24 @@ module Protobuf
|
|
275
334
|
def response_class(endpoint)
|
276
335
|
subject_service.rpcs[endpoint].response_type
|
277
336
|
end
|
337
|
+
|
338
|
+
# Returns the request wrapper that is encoded and sent over the wire when calling
|
339
|
+
# an RPC method with the given request
|
340
|
+
#
|
341
|
+
# @param [Symbol, String] method a symbol or string denoting the method to call.
|
342
|
+
# @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
|
343
|
+
# @return [Protobuf::Socketrpc::Request] the wrapper used to transmit RPC requests.
|
344
|
+
#
|
345
|
+
def wrapped_request(rpc_method, request)
|
346
|
+
request = request_class(rpc_method).new(request) if request.is_a?(Hash)
|
347
|
+
|
348
|
+
::Protobuf::Socketrpc::Request.new(
|
349
|
+
:service_name => subject_service.to_s,
|
350
|
+
:method_name => rpc_method.to_s,
|
351
|
+
:request_proto => request.encode,
|
352
|
+
:caller => 'protobuf-rspec'
|
353
|
+
)
|
354
|
+
end
|
278
355
|
end
|
279
356
|
end
|
280
357
|
end
|
data/protobuf-rspec.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "protobuf/rspec/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "protobuf-rspec"
|
7
7
|
s.version = Protobuf::RSpec::VERSION
|
8
|
-
s.authors = ["BJ Neilsen"]
|
9
|
-
s.email = ["bj.neilsen@gmail.com"]
|
8
|
+
s.authors = ["BJ Neilsen", "Adam Hutchison"]
|
9
|
+
s.email = ["bj.neilsen@gmail.com", "liveh2o@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/localshred/protobuf-rspec"
|
11
11
|
s.summary = %q{Protobuf RSpec helpers for testing services and clients. Meant to be used with the protobuf gem. Decouple external services/clients from each other using the given helper methods.}
|
12
12
|
s.description = s.summary
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency "protobuf", ">=
|
21
|
+
s.add_runtime_dependency "protobuf", ">= 3.0.0.rc1"
|
22
22
|
s.add_runtime_dependency "rspec", "~> 2.8"
|
23
23
|
|
24
24
|
s.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,76 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0.rc1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- BJ Neilsen
|
8
|
+
- Adam Hutchison
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: protobuf
|
16
|
-
requirement:
|
17
|
-
none: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - '>='
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
20
|
+
version: 3.0.0.rc1
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
|
-
version_requirements:
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.0.0.rc1
|
25
28
|
- !ruby/object:Gem::Dependency
|
26
29
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
29
31
|
requirements:
|
30
32
|
- - ~>
|
31
33
|
- !ruby/object:Gem::Version
|
32
34
|
version: '2.8'
|
33
35
|
type: :runtime
|
34
36
|
prerelease: false
|
35
|
-
version_requirements:
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.8'
|
36
42
|
- !ruby/object:Gem::Dependency
|
37
43
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
40
45
|
requirements:
|
41
|
-
- -
|
46
|
+
- - '>='
|
42
47
|
- !ruby/object:Gem::Version
|
43
48
|
version: '0'
|
44
49
|
type: :development
|
45
50
|
prerelease: false
|
46
|
-
version_requirements:
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
47
56
|
- !ruby/object:Gem::Dependency
|
48
57
|
name: yard
|
49
|
-
requirement:
|
50
|
-
none: false
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
51
59
|
requirements:
|
52
60
|
- - ~>
|
53
61
|
- !ruby/object:Gem::Version
|
54
62
|
version: '0.7'
|
55
63
|
type: :development
|
56
64
|
prerelease: false
|
57
|
-
version_requirements:
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.7'
|
58
70
|
- !ruby/object:Gem::Dependency
|
59
71
|
name: redcarpet
|
60
|
-
requirement:
|
61
|
-
none: false
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
64
75
|
- !ruby/object:Gem::Version
|
65
76
|
version: '2.1'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.1'
|
69
84
|
description: Protobuf RSpec helpers for testing services and clients. Meant to be
|
70
85
|
used with the protobuf gem. Decouple external services/clients from each other using
|
71
86
|
the given helper methods.
|
72
87
|
email:
|
73
88
|
- bj.neilsen@gmail.com
|
89
|
+
- liveh2o@gmail.com
|
74
90
|
executables: []
|
75
91
|
extensions: []
|
76
92
|
extra_rdoc_files: []
|
@@ -85,33 +101,26 @@ files:
|
|
85
101
|
- protobuf-rspec.gemspec
|
86
102
|
homepage: http://github.com/localshred/protobuf-rspec
|
87
103
|
licenses: []
|
104
|
+
metadata: {}
|
88
105
|
post_install_message:
|
89
106
|
rdoc_options: []
|
90
107
|
require_paths:
|
91
108
|
- lib
|
92
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
110
|
requirements:
|
95
|
-
- -
|
111
|
+
- - '>='
|
96
112
|
- !ruby/object:Gem::Version
|
97
113
|
version: '0'
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
hash: -623885674851921765
|
101
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
115
|
requirements:
|
104
|
-
- -
|
116
|
+
- - '>'
|
105
117
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
hash: -623885674851921765
|
118
|
+
version: 1.3.1
|
110
119
|
requirements: []
|
111
120
|
rubyforge_project: protobuf-rspec
|
112
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 2.1.2
|
113
122
|
signing_key:
|
114
|
-
specification_version:
|
123
|
+
specification_version: 4
|
115
124
|
summary: Protobuf RSpec helpers for testing services and clients. Meant to be used
|
116
125
|
with the protobuf gem. Decouple external services/clients from each other using
|
117
126
|
the given helper methods.
|