protobuf 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/lib/protobuf/field/base_field.rb +5 -1
- data/lib/protobuf/field/float_field.rb +4 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +31 -20
- data/lib/protobuf/rpc/servers/zmq/broker.rb +1 -1
- data/lib/protobuf/version.rb +1 -1
- data/protobuf.gemspec +1 -1
- data/spec/encoding/all_types_spec.rb +1 -1
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/socket_server_spec.rb +5 -4
- data/spec/functional/zmq_server_spec.rb +7 -7
- data/spec/lib/protobuf/cli_spec.rb +39 -39
- data/spec/lib/protobuf/code_generator_spec.rb +4 -4
- data/spec/lib/protobuf/enum_spec.rb +23 -23
- data/spec/lib/protobuf/field/float_field_spec.rb +55 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +4 -4
- data/spec/lib/protobuf/generators/base_spec.rb +4 -7
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +3 -3
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +4 -4
- data/spec/lib/protobuf/generators/field_generator_spec.rb +11 -11
- data/spec/lib/protobuf/generators/file_generator_spec.rb +3 -3
- data/spec/lib/protobuf/generators/service_generator_spec.rb +2 -2
- data/spec/lib/protobuf/lifecycle_spec.rb +16 -16
- data/spec/lib/protobuf/logger_spec.rb +27 -27
- data/spec/lib/protobuf/message_spec.rb +42 -42
- data/spec/lib/protobuf/optionable_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/client_spec.rb +13 -13
- data/spec/lib/protobuf/rpc/connector_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +31 -33
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +8 -8
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +24 -35
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +8 -8
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +10 -10
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +5 -5
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +26 -27
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +39 -39
- data/spec/lib/protobuf/rpc/service_spec.rb +27 -27
- data/spec/lib/protobuf/rpc/stat_spec.rb +4 -4
- data/spec/lib/protobuf_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -0
- data/spec/support/packed_field.rb +1 -1
- metadata +6 -76
@@ -17,12 +17,12 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
|
17
17
|
describe "#call" do
|
18
18
|
it "encodes the response" do
|
19
19
|
stack_env = subject.call(env)
|
20
|
-
stack_env.encoded_response.
|
20
|
+
expect(stack_env.encoded_response).to eq encoded_response
|
21
21
|
end
|
22
22
|
|
23
23
|
it "calls the stack" do
|
24
24
|
stack_env = subject.call(env)
|
25
|
-
stack_env.response.
|
25
|
+
expect(stack_env.response).to eq response
|
26
26
|
end
|
27
27
|
|
28
28
|
context "when response is responds to :to_hash" do
|
@@ -31,7 +31,7 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
|
31
31
|
|
32
32
|
it "sets Env#response" do
|
33
33
|
stack_env = subject.call(env)
|
34
|
-
stack_env.response.
|
34
|
+
expect(stack_env.response).to eq response
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -41,7 +41,7 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
|
41
41
|
|
42
42
|
it "sets Env#response" do
|
43
43
|
stack_env = subject.call(env)
|
44
|
-
stack_env.response.
|
44
|
+
expect(stack_env.response).to eq response
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -60,12 +60,12 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
|
60
60
|
|
61
61
|
it "wraps and encodes the response" do
|
62
62
|
stack_env = subject.call(env)
|
63
|
-
stack_env.encoded_response.
|
63
|
+
expect(stack_env.encoded_response).to eq encoded_response
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
context "when encoding fails" do
|
68
|
-
before { Protobuf::Socketrpc::Response.
|
68
|
+
before { allow_any_instance_of(Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) }
|
69
69
|
|
70
70
|
it "raises a bad request data exception" do
|
71
71
|
expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError)
|
@@ -24,15 +24,15 @@ describe Protobuf::Rpc::Socket::Server do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "Runner provides a stop method" do
|
27
|
-
@runner.
|
27
|
+
expect(@runner).to respond_to(:stop)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "provides a stop method" do
|
31
|
-
@server.
|
31
|
+
expect(@server).to respond_to(:stop)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "signals the Server is running" do
|
35
|
-
@server.
|
35
|
+
expect(@server).to be_running
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -22,12 +22,12 @@ describe Protobuf::Rpc::Zmq::Server do
|
|
22
22
|
describe '.running?' do
|
23
23
|
it 'returns true if running' do
|
24
24
|
subject.instance_variable_set(:@running, true)
|
25
|
-
subject.running
|
25
|
+
expect(subject.running?).to be_truthy
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'returns false if not running' do
|
29
29
|
subject.instance_variable_set(:@running, false)
|
30
|
-
subject.running
|
30
|
+
expect(subject.running?).to be_falsey
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ describe Protobuf::Rpc::Zmq::Server do
|
|
35
35
|
it 'sets running to false' do
|
36
36
|
subject.instance_variable_set(:@workers, [])
|
37
37
|
subject.stop
|
38
|
-
subject.instance_variable_get(:@running).
|
38
|
+
expect(subject.instance_variable_get(:@running)).to be_falsey
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -18,7 +18,7 @@ describe ::Protobuf::Rpc::Zmq::Util do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'retrieves the error string from ZeroMQ' do
|
21
|
-
ZMQ::Util.
|
21
|
+
allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq')
|
22
22
|
expect {
|
23
23
|
subject.zmq_error_check(-1, :test)
|
24
24
|
}.to raise_error(RuntimeError, /an error from zmq/i)
|
@@ -39,7 +39,7 @@ describe ::Protobuf::Rpc::Zmq::Util do
|
|
39
39
|
|
40
40
|
describe '#log_signature' do
|
41
41
|
it 'returns the signature for the log' do
|
42
|
-
subject.log_signature.
|
42
|
+
expect(subject.log_signature).to include('server', 'UtilTest')
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ::Protobuf::Rpc::Zmq::Worker do
|
4
|
-
before(:each) do
|
4
|
+
before(:each) do
|
5
5
|
load 'protobuf/zmq.rb'
|
6
6
|
|
7
7
|
fake_socket = double
|
8
|
-
fake_socket.
|
9
|
-
fake_socket.
|
8
|
+
expect(fake_socket).to receive(:connect).and_return(0)
|
9
|
+
expect(fake_socket).to receive(:send_string).and_return(0)
|
10
10
|
|
11
11
|
fake_context = double
|
12
|
-
fake_context.
|
13
|
-
::ZMQ::Context.
|
12
|
+
expect(fake_context).to receive(:socket).and_return(fake_socket)
|
13
|
+
expect(::ZMQ::Context).to receive(:new).and_return(fake_context)
|
14
14
|
end
|
15
15
|
|
16
16
|
subject do
|
@@ -56,10 +56,9 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def expect_event_trigger(event)
|
59
|
-
::ActiveSupport::Notifications
|
60
|
-
|
61
|
-
|
62
|
-
.once
|
59
|
+
expect(::ActiveSupport::Notifications).to receive(:instrument)
|
60
|
+
.with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing)))
|
61
|
+
.once
|
63
62
|
end
|
64
63
|
|
65
64
|
def send_beacon(type, server)
|
@@ -74,29 +73,29 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
74
73
|
end
|
75
74
|
|
76
75
|
it "should be a singleton" do
|
77
|
-
subject.
|
76
|
+
expect(subject).to be_a_kind_of(Singleton)
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should be configured to listen to address 127.0.0.1" do
|
81
|
-
described_class.address.
|
80
|
+
expect(described_class.address).to eq '127.0.0.1'
|
82
81
|
end
|
83
82
|
|
84
83
|
it "should be configured to listen to port 33333" do
|
85
|
-
described_class.port.
|
84
|
+
expect(described_class.port).to eq 33333
|
86
85
|
end
|
87
86
|
|
88
87
|
it "should defer .start to the instance#start" do
|
89
|
-
described_class.instance.
|
88
|
+
expect(described_class.instance).to receive(:start)
|
90
89
|
described_class.start
|
91
90
|
end
|
92
91
|
|
93
92
|
it "should yeild itself to blocks passed to .start" do
|
94
|
-
described_class.instance.
|
93
|
+
allow(described_class.instance).to receive(:start)
|
95
94
|
expect { |b| described_class.start(&b) }.to yield_with_args(described_class)
|
96
95
|
end
|
97
96
|
|
98
97
|
it "should defer .stop to the instance#stop" do
|
99
|
-
described_class.instance.
|
98
|
+
expect(described_class.instance).to receive(:stop)
|
100
99
|
described_class.stop
|
101
100
|
end
|
102
101
|
|
@@ -106,20 +105,20 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
106
105
|
describe "#lookup" do
|
107
106
|
it "should return nil" do
|
108
107
|
send_beacon(:heartbeat, echo_server)
|
109
|
-
subject.lookup("EchoService").
|
108
|
+
expect(subject.lookup("EchoService")).to be_nil
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
113
112
|
describe "#restart" do
|
114
113
|
it "should start the service" do
|
115
114
|
subject.restart
|
116
|
-
subject.
|
115
|
+
expect(subject).to be_running
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
119
|
describe "#running" do
|
121
120
|
it "should be false" do
|
122
|
-
subject.
|
121
|
+
expect(subject).to_not be_running
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
@@ -134,7 +133,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
134
133
|
before { subject.start }
|
135
134
|
after { subject.stop }
|
136
135
|
|
137
|
-
|
136
|
+
specify { expect(subject).to be_running }
|
138
137
|
|
139
138
|
it "should trigger added events" do
|
140
139
|
expect_event_trigger("directory.listing.added")
|
@@ -159,13 +158,13 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
159
158
|
send_beacon(:heartbeat, hello_server)
|
160
159
|
send_beacon(:heartbeat, combo_server)
|
161
160
|
|
162
|
-
subject.all_listings_for("HelloService").size.
|
161
|
+
expect(subject.all_listings_for("HelloService").size).to eq(2)
|
163
162
|
end
|
164
163
|
end
|
165
164
|
|
166
165
|
context "when no listings are present" do
|
167
166
|
it "returns and empty array" do
|
168
|
-
subject.all_listings_for("HelloService").size.
|
167
|
+
expect(subject.all_listings_for("HelloService").size).to eq(0)
|
169
168
|
end
|
170
169
|
end
|
171
170
|
end
|
@@ -185,7 +184,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
185
184
|
describe "#lookup" do
|
186
185
|
it "should provide listings by service" do
|
187
186
|
send_beacon(:heartbeat, hello_server)
|
188
|
-
subject.lookup("HelloService").to_hash.
|
187
|
+
expect(subject.lookup("HelloService").to_hash).to eq hello_server.to_hash
|
189
188
|
end
|
190
189
|
|
191
190
|
it "should return random listings" do
|
@@ -193,14 +192,14 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
193
192
|
send_beacon(:heartbeat, combo_server)
|
194
193
|
|
195
194
|
uuids = 100.times.map { subject.lookup("HelloService").uuid }
|
196
|
-
uuids.count("hello").
|
197
|
-
uuids.count("combo").
|
195
|
+
expect(uuids.count("hello")).to be_within(25).of(50)
|
196
|
+
expect(uuids.count("combo")).to be_within(25).of(50)
|
198
197
|
end
|
199
198
|
|
200
199
|
it "should not return expired listings" do
|
201
200
|
send_beacon(:heartbeat, hello_server_with_short_ttl)
|
202
201
|
sleep 1
|
203
|
-
subject.lookup("HelloService").
|
202
|
+
expect(subject.lookup("HelloService")).to be_nil
|
204
203
|
end
|
205
204
|
|
206
205
|
it "should not return flatlined servers" do
|
@@ -209,7 +208,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
209
208
|
send_beacon(:flatline, echo_server)
|
210
209
|
|
211
210
|
uuids = 100.times.map { subject.lookup("EchoService").uuid }
|
212
|
-
uuids.count("combo").
|
211
|
+
expect(uuids.count("combo")).to eq 100
|
213
212
|
end
|
214
213
|
|
215
214
|
it "should return up-to-date listings" do
|
@@ -217,13 +216,13 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
217
216
|
echo_server.port = "7777"
|
218
217
|
send_beacon(:heartbeat, echo_server)
|
219
218
|
|
220
|
-
subject.lookup("EchoService").port.
|
219
|
+
expect(subject.lookup("EchoService").port).to eq "7777"
|
221
220
|
end
|
222
221
|
|
223
222
|
context 'when given service identifier is a class name' do
|
224
223
|
it 'returns the listing corresponding to the class name' do
|
225
224
|
send_beacon(:heartbeat, echo_server)
|
226
|
-
subject.lookup(EchoService).uuid.
|
225
|
+
expect(subject.lookup(EchoService).uuid).to eq echo_server.uuid
|
227
226
|
end
|
228
227
|
end
|
229
228
|
end
|
@@ -233,13 +232,13 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
233
232
|
send_beacon(:heartbeat, echo_server)
|
234
233
|
send_beacon(:heartbeat, combo_server)
|
235
234
|
subject.restart
|
236
|
-
subject.lookup("EchoService").
|
235
|
+
expect(subject.lookup("EchoService")).to be_nil
|
237
236
|
end
|
238
237
|
end
|
239
238
|
|
240
239
|
describe "#running" do
|
241
240
|
it "should be true" do
|
242
|
-
subject.
|
241
|
+
expect(subject).to be_running
|
243
242
|
end
|
244
243
|
end
|
245
244
|
|
@@ -248,12 +247,12 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
248
247
|
send_beacon(:heartbeat, echo_server)
|
249
248
|
send_beacon(:heartbeat, combo_server)
|
250
249
|
subject.stop
|
251
|
-
subject.lookup("EchoService").
|
250
|
+
expect(subject.lookup("EchoService")).to be_nil
|
252
251
|
end
|
253
252
|
|
254
253
|
it "should stop the server" do
|
255
254
|
subject.stop
|
256
|
-
subject.
|
255
|
+
expect(subject).to_not be_running
|
257
256
|
end
|
258
257
|
end
|
259
258
|
end
|
@@ -23,14 +23,14 @@ describe Protobuf::Rpc::ServiceDispatcher do
|
|
23
23
|
|
24
24
|
subject { described_class.new(app) }
|
25
25
|
|
26
|
-
before { subject.
|
26
|
+
before { allow(subject).to receive(:rpc_service).and_return(rpc_service) }
|
27
27
|
|
28
28
|
describe '#call' do
|
29
|
-
before { rpc_service.
|
29
|
+
before { allow(rpc_service).to receive(:response).and_return(response) }
|
30
30
|
|
31
31
|
it "dispatches the request" do
|
32
32
|
stack_env = subject.call(env)
|
33
|
-
stack_env.response.
|
33
|
+
expect(stack_env.response).to eq response
|
34
34
|
end
|
35
35
|
|
36
36
|
context "when the given RPC method is not implemented" do
|
@@ -42,7 +42,7 @@ describe Protobuf::Rpc::ServiceDispatcher do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context "when the given RPC method is implemented and a NoMethodError is raised" do
|
45
|
-
before { rpc_service.
|
45
|
+
before { allow(rpc_service).to receive(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) }
|
46
46
|
|
47
47
|
it "raises the exeception" do
|
48
48
|
expect { subject.call(env) }.to raise_exception(NoMethodError)
|
@@ -55,13 +55,13 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
55
55
|
FilterTest.before_filter(:foo)
|
56
56
|
end
|
57
57
|
|
58
|
-
specify { subject.class.
|
59
|
-
specify { subject.class.
|
58
|
+
specify { expect(subject.class).to respond_to(:before_filter) }
|
59
|
+
specify { expect(subject.class).to respond_to(:before_action) }
|
60
60
|
|
61
61
|
it 'calls filters in the order they were defined' do
|
62
62
|
subject.__send__(:run_filters, :endpoint)
|
63
|
-
subject.called.
|
64
|
-
subject.before_filter_calls.
|
63
|
+
expect(subject.called).to eq [ :verify_before, :foo, :endpoint ]
|
64
|
+
expect(subject.before_filter_calls).to eq 1
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'when filter is configured with "only"' do
|
@@ -82,14 +82,14 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
82
82
|
context 'when invoking a method defined in "only" option' do
|
83
83
|
it 'invokes the filter' do
|
84
84
|
subject.__send__(:run_filters, :endpoint_with_verify)
|
85
|
-
subject.called.
|
85
|
+
expect(subject.called).to eq [ :verify_before, :endpoint_with_verify ]
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
context 'when invoking a method not defined by "only" option' do
|
90
90
|
it 'does not invoke the filter' do
|
91
91
|
subject.__send__(:run_filters, :endpoint)
|
92
|
-
subject.called.
|
92
|
+
expect(subject.called).to eq [ :endpoint ]
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -112,14 +112,14 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
112
112
|
context 'when invoking a method not defined in "except" option' do
|
113
113
|
it 'invokes the filter' do
|
114
114
|
subject.__send__(:run_filters, :endpoint)
|
115
|
-
subject.called.
|
115
|
+
expect(subject.called).to eq [ :verify_before, :endpoint ]
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
context 'when invoking a method defined by "except" option' do
|
120
120
|
it 'does not invoke the filter' do
|
121
121
|
subject.__send__(:run_filters, :endpoint_without_verify)
|
122
|
-
subject.called.
|
122
|
+
expect(subject.called).to eq [ :endpoint_without_verify ]
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
@@ -142,7 +142,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
142
142
|
|
143
143
|
it 'invokes the filter' do
|
144
144
|
subject.__send__(:run_filters, :endpoint)
|
145
|
-
subject.called.
|
145
|
+
expect(subject.called).to eq [ :verify_before, :endpoint ]
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -154,7 +154,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
154
154
|
|
155
155
|
it 'invokes the filter' do
|
156
156
|
subject.__send__(:run_filters, :endpoint)
|
157
|
-
subject.called.
|
157
|
+
expect(subject.called).to eq [ :verify_before, :endpoint ]
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -166,7 +166,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
166
166
|
|
167
167
|
it 'skips the filter' do
|
168
168
|
subject.__send__(:run_filters, :endpoint)
|
169
|
-
subject.called.
|
169
|
+
expect(subject.called).to eq [ :endpoint ]
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
@@ -178,7 +178,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
178
178
|
|
179
179
|
it 'skips the filter' do
|
180
180
|
subject.__send__(:run_filters, :endpoint)
|
181
|
-
subject.called.
|
181
|
+
expect(subject.called).to eq [ :endpoint ]
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
@@ -201,7 +201,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
201
201
|
|
202
202
|
it 'invokes the filter' do
|
203
203
|
subject.__send__(:run_filters, :endpoint)
|
204
|
-
subject.called.
|
204
|
+
expect(subject.called).to eq [ :verify_before, :endpoint ]
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
@@ -213,7 +213,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
213
213
|
|
214
214
|
it 'invokes the filter' do
|
215
215
|
subject.__send__(:run_filters, :endpoint)
|
216
|
-
subject.called.
|
216
|
+
expect(subject.called).to eq [ :verify_before, :endpoint ]
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
@@ -225,7 +225,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
225
225
|
|
226
226
|
it 'skips the filter' do
|
227
227
|
subject.__send__(:run_filters, :endpoint)
|
228
|
-
subject.called.
|
228
|
+
expect(subject.called).to eq [ :endpoint ]
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -237,7 +237,7 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
237
237
|
|
238
238
|
it 'skips the filter' do
|
239
239
|
subject.__send__(:run_filters, :endpoint)
|
240
|
-
subject.called.
|
240
|
+
expect(subject.called).to eq [ :endpoint ]
|
241
241
|
end
|
242
242
|
end
|
243
243
|
end
|
@@ -259,9 +259,9 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
259
259
|
end
|
260
260
|
|
261
261
|
it 'does not invoke the rpc method' do
|
262
|
-
subject.
|
262
|
+
expect(subject).not_to receive(:endpoint)
|
263
263
|
subject.__send__(:run_filters, :endpoint)
|
264
|
-
subject.called.
|
264
|
+
expect(subject.called).to eq [ :short_circuit_filter ]
|
265
265
|
end
|
266
266
|
end
|
267
267
|
end
|
@@ -289,13 +289,13 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
289
289
|
FilterTest.after_filter(:foo)
|
290
290
|
end
|
291
291
|
|
292
|
-
specify { subject.class.
|
293
|
-
specify { subject.class.
|
292
|
+
specify { expect(subject.class).to respond_to(:after_filter) }
|
293
|
+
specify { expect(subject.class).to respond_to(:after_action) }
|
294
294
|
|
295
295
|
it 'calls filters in the order they were defined' do
|
296
296
|
subject.__send__(:run_filters, :endpoint)
|
297
|
-
subject.called.
|
298
|
-
subject.after_filter_calls.
|
297
|
+
expect(subject.called).to eq [ :endpoint, :verify_after, :foo ]
|
298
|
+
expect(subject.after_filter_calls).to eq 1
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
@@ -326,12 +326,12 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
326
326
|
FilterTest.around_filter(:inner_around)
|
327
327
|
end
|
328
328
|
|
329
|
-
specify { subject.class.
|
330
|
-
specify { subject.class.
|
329
|
+
specify { expect(subject.class).to respond_to(:around_filter) }
|
330
|
+
specify { expect(subject.class).to respond_to(:around_action) }
|
331
331
|
|
332
332
|
it 'calls filters in the order they were defined' do
|
333
333
|
subject.__send__(:run_filters, :endpoint)
|
334
|
-
subject.called.
|
334
|
+
expect(subject.called).to eq([ :outer_around_top,
|
335
335
|
:inner_around_top,
|
336
336
|
:endpoint,
|
337
337
|
:inner_around_bottom,
|
@@ -354,9 +354,9 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
354
354
|
end
|
355
355
|
|
356
356
|
it 'cancels calling the rest of the filters and the endpoint' do
|
357
|
-
subject.
|
357
|
+
expect(subject).not_to receive(:endpoint)
|
358
358
|
subject.__send__(:run_filters, :endpoint)
|
359
|
-
subject.called.
|
359
|
+
expect(subject.called).to eq([ :outer_around_top,
|
360
360
|
:inner_around,
|
361
361
|
:outer_around_bottom ])
|
362
362
|
end
|
@@ -412,10 +412,10 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
412
412
|
|
413
413
|
it 'short-circuits the call stack' do
|
414
414
|
expect {
|
415
|
-
subject.
|
415
|
+
expect(subject).not_to receive(:endpoint)
|
416
416
|
subject.__send__(:run_filters, :endpoint)
|
417
|
-
subject.called.
|
418
|
-
subject.ex_class.
|
417
|
+
expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ])
|
418
|
+
expect(subject.ex_class).to eq CustomError3
|
419
419
|
}.not_to raise_error
|
420
420
|
end
|
421
421
|
end
|
@@ -433,10 +433,10 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
433
433
|
|
434
434
|
it 'short-circuits the call stack' do
|
435
435
|
expect {
|
436
|
-
subject.
|
436
|
+
expect(subject).not_to receive(:endpoint)
|
437
437
|
subject.__send__(:run_filters, :endpoint)
|
438
|
-
subject.called.
|
439
|
-
subject.ex_class.
|
438
|
+
expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ])
|
439
|
+
expect(subject.ex_class).to eq CustomError1
|
440
440
|
}.not_to raise_error
|
441
441
|
end
|
442
442
|
end
|
@@ -453,10 +453,10 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
453
453
|
|
454
454
|
it 'short-circuits the call stack' do
|
455
455
|
expect {
|
456
|
-
subject.
|
456
|
+
expect(subject).not_to receive(:endpoint)
|
457
457
|
subject.__send__(:run_filters, :endpoint)
|
458
|
-
subject.called.
|
459
|
-
subject.ex_class.
|
458
|
+
expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ])
|
459
|
+
expect(subject.ex_class).to eq CustomError1
|
460
460
|
}.not_to raise_error
|
461
461
|
end
|
462
462
|
end
|
@@ -472,10 +472,10 @@ describe Protobuf::Rpc::ServiceFilters do
|
|
472
472
|
|
473
473
|
it 'rescues with the given callable' do
|
474
474
|
expect {
|
475
|
-
subject.
|
475
|
+
expect(subject).not_to receive(:endpoint)
|
476
476
|
subject.__send__(:run_filters, :endpoint)
|
477
|
-
subject.called.
|
478
|
-
subject.ex_class.
|
477
|
+
expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ])
|
478
|
+
expect(subject.ex_class).to eq RuntimeError
|
479
479
|
}.not_to raise_error
|
480
480
|
end
|
481
481
|
end
|