protobuf 3.3.6 → 3.4.0
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/.rubocop.yml +48 -0
- data/.rubocop_todo.yml +79 -0
- data/.travis.yml +12 -4
- data/Rakefile +14 -11
- data/bin/protoc-gen-ruby +0 -1
- data/bin/rpc_server +1 -0
- data/install-protobuf.sh +8 -0
- data/lib/protobuf.rb +30 -24
- data/lib/protobuf/cli.rb +35 -35
- data/lib/protobuf/code_generator.rb +11 -8
- data/lib/protobuf/decoder.rb +4 -5
- data/lib/protobuf/deprecation.rb +20 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
- data/lib/protobuf/encoder.rb +9 -4
- data/lib/protobuf/enum.rb +38 -54
- data/lib/protobuf/field.rb +2 -2
- data/lib/protobuf/field/base_field.rb +28 -32
- data/lib/protobuf/field/bool_field.rb +4 -4
- data/lib/protobuf/field/bytes_field.rb +5 -4
- data/lib/protobuf/field/double_field.rb +0 -1
- data/lib/protobuf/field/enum_field.rb +4 -7
- data/lib/protobuf/field/field_array.rb +3 -4
- data/lib/protobuf/field/fixed32_field.rb +1 -1
- data/lib/protobuf/field/fixed64_field.rb +0 -1
- data/lib/protobuf/field/float_field.rb +0 -1
- data/lib/protobuf/field/int32_field.rb +0 -1
- data/lib/protobuf/field/int64_field.rb +0 -1
- data/lib/protobuf/field/integer_field.rb +0 -1
- data/lib/protobuf/field/message_field.rb +2 -3
- data/lib/protobuf/field/sfixed32_field.rb +0 -1
- data/lib/protobuf/field/sfixed64_field.rb +0 -1
- data/lib/protobuf/field/signed_integer_field.rb +0 -1
- data/lib/protobuf/field/sint32_field.rb +0 -1
- data/lib/protobuf/field/sint64_field.rb +0 -1
- data/lib/protobuf/field/string_field.rb +0 -1
- data/lib/protobuf/field/uint32_field.rb +0 -1
- data/lib/protobuf/field/uint64_field.rb +0 -1
- data/lib/protobuf/field/varint_field.rb +0 -1
- data/lib/protobuf/generators/base.rb +1 -2
- data/lib/protobuf/generators/enum_generator.rb +1 -2
- data/lib/protobuf/generators/extension_generator.rb +1 -2
- data/lib/protobuf/generators/field_generator.rb +4 -5
- data/lib/protobuf/generators/file_generator.rb +22 -27
- data/lib/protobuf/generators/group_generator.rb +15 -16
- data/lib/protobuf/generators/message_generator.rb +13 -14
- data/lib/protobuf/generators/printable.rb +9 -10
- data/lib/protobuf/generators/service_generator.rb +1 -2
- data/lib/protobuf/lifecycle.rb +20 -33
- data/lib/protobuf/logging.rb +4 -6
- data/lib/protobuf/message.rb +22 -16
- data/lib/protobuf/message/fields.rb +14 -17
- data/lib/protobuf/message/serialization.rb +6 -5
- data/lib/protobuf/rpc/buffer.rb +10 -12
- data/lib/protobuf/rpc/client.rb +12 -12
- data/lib/protobuf/rpc/connectors/base.rb +4 -3
- data/lib/protobuf/rpc/connectors/common.rb +15 -17
- data/lib/protobuf/rpc/connectors/socket.rb +2 -2
- data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
- data/lib/protobuf/rpc/env.rb +12 -12
- data/lib/protobuf/rpc/error.rb +1 -1
- data/lib/protobuf/rpc/error/client_error.rb +4 -4
- data/lib/protobuf/rpc/error/server_error.rb +6 -6
- data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
- data/lib/protobuf/rpc/middleware/logger.rb +3 -3
- data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
- data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
- data/lib/protobuf/rpc/rpc.pb.rb +2 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
- data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
- data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
- data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
- data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
- data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
- data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
- data/lib/protobuf/rpc/service.rb +15 -15
- data/lib/protobuf/rpc/service_directory.rb +7 -11
- data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
- data/lib/protobuf/rpc/service_filters.rb +27 -28
- data/lib/protobuf/rpc/stat.rb +4 -7
- data/lib/protobuf/socket.rb +0 -1
- data/lib/protobuf/tasks/compile.rake +2 -2
- data/lib/protobuf/version.rb +1 -1
- data/protobuf.gemspec +20 -4
- data/spec/benchmark/tasks.rb +49 -23
- data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
- data/spec/encoding/all_types_spec.rb +91 -77
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/socket_server_spec.rb +9 -10
- data/spec/functional/zmq_server_spec.rb +21 -19
- data/spec/lib/protobuf/cli_spec.rb +20 -20
- data/spec/lib/protobuf/code_generator_spec.rb +6 -6
- data/spec/lib/protobuf/enum_spec.rb +57 -31
- data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
- data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
- data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
- data/spec/lib/protobuf/field_spec.rb +3 -6
- data/spec/lib/protobuf/generators/base_spec.rb +6 -6
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
- data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
- data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
- data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
- data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
- data/spec/lib/protobuf/message_spec.rb +63 -35
- data/spec/lib/protobuf/optionable_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
- data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
- data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
- data/spec/lib/protobuf_spec.rb +9 -9
- data/spec/spec_helper.rb +7 -19
- data/spec/support/server.rb +29 -59
- data/spec/support/test/defaults.pb.rb +2 -0
- data/spec/support/test/enum.pb.rb +2 -0
- data/spec/support/test/extended.pb.rb +2 -0
- data/spec/support/test/google_unittest_import.pb.rb +2 -0
- data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
- data/spec/support/test/multi_field_extensions.pb.rb +2 -0
- data/spec/support/test/resource.pb.rb +2 -0
- data/spec/support/test/resource_service.rb +17 -20
- metadata +153 -112
- data/lib/protobuf/deprecator.rb +0 -42
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'spec/support/test/resource_service'
|
3
3
|
|
4
|
-
describe 'Functional Socket Client' do
|
4
|
+
RSpec.describe 'Functional Socket Client' do
|
5
5
|
before(:all) do
|
6
6
|
load "protobuf/socket.rb"
|
7
7
|
@options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
@@ -16,7 +16,7 @@ describe 'Functional Socket Client' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'runs fine when required fields are set' do
|
19
|
-
expect
|
19
|
+
expect do
|
20
20
|
client = ::Test::ResourceService.client
|
21
21
|
|
22
22
|
client.find(:name => 'Test Name', :active => true) do |c|
|
@@ -26,10 +26,10 @@ describe 'Functional Socket Client' do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
c.on_failure do |err|
|
29
|
-
|
29
|
+
fail err.inspect
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
end.to_not raise_error
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'calls the on_failure callback when a message is malformed' do
|
@@ -38,11 +38,11 @@ describe 'Functional Socket Client' do
|
|
38
38
|
client = ::Test::ResourceService.client
|
39
39
|
|
40
40
|
client.find(request) do |c|
|
41
|
-
c.on_success {
|
42
|
-
c.on_failure {|e| error = e}
|
41
|
+
c.on_success { fail "shouldn't pass" }
|
42
|
+
c.on_failure { |e| error = e }
|
43
43
|
end
|
44
44
|
|
45
|
-
expect(error.message).to match(/
|
45
|
+
expect(error.message).to match(/Required field.*does not have a value/)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'calls the on_failure callback when the request type is wrong' do
|
@@ -51,10 +51,9 @@ describe 'Functional Socket Client' do
|
|
51
51
|
client = ::Test::ResourceService.client
|
52
52
|
|
53
53
|
client.find(request) do |c|
|
54
|
-
c.on_success {
|
55
|
-
c.on_failure {|e| error = e}
|
54
|
+
c.on_success { fail "shouldn't pass" }
|
55
|
+
c.on_failure { |e| error = e }
|
56
56
|
end
|
57
57
|
expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
@@ -3,15 +3,17 @@ require 'spec_helper'
|
|
3
3
|
require 'spec/support/test/resource_service'
|
4
4
|
require 'protobuf/rpc/service_directory'
|
5
5
|
|
6
|
-
describe 'Functional ZMQ Client' do
|
6
|
+
RSpec.describe 'Functional ZMQ Client' do
|
7
7
|
before(:all) do
|
8
8
|
load "protobuf/zmq.rb"
|
9
|
-
@runner = ::Protobuf::Rpc::ZmqRunner.new(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
@runner = ::Protobuf::Rpc::ZmqRunner.new(
|
10
|
+
:host => "127.0.0.1",
|
11
|
+
:port => 9399,
|
12
|
+
:worker_port => 9408,
|
13
|
+
:backlog => 100,
|
14
|
+
:threshold => 100,
|
15
|
+
:threads => 5,
|
16
|
+
)
|
15
17
|
@server_thread = Thread.new(@runner) { |runner| runner.run }
|
16
18
|
Thread.pass until @runner.running?
|
17
19
|
end
|
@@ -22,7 +24,7 @@ describe 'Functional ZMQ Client' do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'runs fine when required fields are set' do
|
25
|
-
expect
|
27
|
+
expect do
|
26
28
|
client = ::Test::ResourceService.client
|
27
29
|
|
28
30
|
client.find(:name => 'Test Name', :active => true) do |c|
|
@@ -32,15 +34,15 @@ describe 'Functional ZMQ Client' do
|
|
32
34
|
end
|
33
35
|
|
34
36
|
c.on_failure do |err|
|
35
|
-
|
37
|
+
fail err.inspect
|
36
38
|
end
|
37
39
|
end
|
38
|
-
|
40
|
+
end.to_not raise_error
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'runs under heavy load' do
|
42
|
-
10.times do
|
43
|
-
5.times.map do
|
44
|
+
10.times do
|
45
|
+
5.times.map do
|
44
46
|
Thread.new do
|
45
47
|
client = ::Test::ResourceService.client
|
46
48
|
|
@@ -51,7 +53,7 @@ describe 'Functional ZMQ Client' do
|
|
51
53
|
end
|
52
54
|
|
53
55
|
c.on_failure do |err|
|
54
|
-
|
56
|
+
fail err.inspect
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -66,10 +68,10 @@ describe 'Functional ZMQ Client' do
|
|
66
68
|
client = ::Test::ResourceService.client
|
67
69
|
|
68
70
|
client.find(request) do |c|
|
69
|
-
c.on_success {
|
70
|
-
c.on_failure {|e| error = e }
|
71
|
+
c.on_success { fail "shouldn't pass" }
|
72
|
+
c.on_failure { |e| error = e }
|
71
73
|
end
|
72
|
-
expect(error.message).to match(/
|
74
|
+
expect(error.message).to match(/Required field.*does not have a value/)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -80,8 +82,8 @@ describe 'Functional ZMQ Client' do
|
|
80
82
|
client = ::Test::ResourceService.client
|
81
83
|
|
82
84
|
client.find(request) do |c|
|
83
|
-
c.on_success {
|
84
|
-
c.on_failure {|e| error = e}
|
85
|
+
c.on_success { fail "shouldn't pass" }
|
86
|
+
c.on_failure { |e| error = e }
|
85
87
|
end
|
86
88
|
expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
87
89
|
end
|
@@ -93,7 +95,7 @@ describe 'Functional ZMQ Client' do
|
|
93
95
|
client = ::Test::ResourceService.client(:timeout => 1)
|
94
96
|
|
95
97
|
client.find_with_sleep(:sleep => 2) do |c|
|
96
|
-
c.on_success {
|
98
|
+
c.on_success { fail "shouldn't pass" }
|
97
99
|
c.on_failure { |e| error = e }
|
98
100
|
end
|
99
101
|
expect(error.message).to match(/The server repeatedly failed to respond/)
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/cli'
|
3
3
|
|
4
|
-
describe ::Protobuf::CLI do
|
4
|
+
RSpec.describe ::Protobuf::CLI do
|
5
5
|
|
6
6
|
let(:app_file) do
|
7
7
|
File.expand_path('../../../support/test_app_file.rb', __FILE__)
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:sock_runner)
|
10
|
+
let(:sock_runner) do
|
11
11
|
runner = double("SocketRunner", :register_signals => nil)
|
12
12
|
allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind"))
|
13
13
|
runner
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
|
-
let(:zmq_runner)
|
17
|
-
runner = double
|
16
|
+
let(:zmq_runner) do
|
17
|
+
runner = double("ZmqRunner", :register_signals => nil)
|
18
18
|
allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind"))
|
19
19
|
runner
|
20
|
-
|
20
|
+
end
|
21
21
|
|
22
22
|
around(:each) do |example|
|
23
23
|
logger = ::Protobuf::Logging.logger
|
@@ -31,12 +31,12 @@ describe ::Protobuf::CLI do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe '#start' do
|
34
|
-
let(:base_args) { [
|
34
|
+
let(:base_args) { ['start', app_file] }
|
35
35
|
let(:test_args) { [] }
|
36
36
|
let(:args) { base_args + test_args }
|
37
37
|
|
38
38
|
context 'host option' do
|
39
|
-
let(:test_args) { [
|
39
|
+
let(:test_args) { ['--host=123.123.123.123'] }
|
40
40
|
|
41
41
|
it 'sends the host option to the runner' do
|
42
42
|
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
@@ -47,7 +47,7 @@ describe ::Protobuf::CLI do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'port option' do
|
50
|
-
let(:test_args) { [
|
50
|
+
let(:test_args) { ['--port=12345'] }
|
51
51
|
|
52
52
|
it 'sends the port option to the runner' do
|
53
53
|
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
@@ -58,7 +58,7 @@ describe ::Protobuf::CLI do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'threads option' do
|
61
|
-
let(:test_args) { [
|
61
|
+
let(:test_args) { ['--threads=500'] }
|
62
62
|
|
63
63
|
it 'sends the threads option to the runner' do
|
64
64
|
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
@@ -69,7 +69,7 @@ describe ::Protobuf::CLI do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'backlog option' do
|
72
|
-
let(:test_args) { [
|
72
|
+
let(:test_args) { ['--backlog=500'] }
|
73
73
|
|
74
74
|
it 'sends the backlog option to the runner' do
|
75
75
|
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
@@ -80,7 +80,7 @@ describe ::Protobuf::CLI do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'threshold option' do
|
83
|
-
let(:test_args) { [
|
83
|
+
let(:test_args) { ['--threshold=500'] }
|
84
84
|
|
85
85
|
it 'sends the backlog option to the runner' do
|
86
86
|
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
@@ -91,7 +91,7 @@ describe ::Protobuf::CLI do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
context 'log options' do
|
94
|
-
let(:test_args) { [
|
94
|
+
let(:test_args) { ['--log=mylog.log', '--level=0'] }
|
95
95
|
|
96
96
|
it 'sends the log file and level options to the runner' do
|
97
97
|
expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level|
|
@@ -115,7 +115,7 @@ describe ::Protobuf::CLI do
|
|
115
115
|
|
116
116
|
unless defined?(JRUBY_VERSION)
|
117
117
|
context 'request pausing' do
|
118
|
-
let(:test_args) { [
|
118
|
+
let(:test_args) { ['--gc_pause_request'] }
|
119
119
|
|
120
120
|
it 'sets the configuration option to GC pause server request' do
|
121
121
|
described_class.start(args)
|
@@ -150,7 +150,7 @@ describe ::Protobuf::CLI do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
context 'when enabled' do
|
153
|
-
let(:test_args) { [
|
153
|
+
let(:test_args) { ['--print_deprecation_warnings'] }
|
154
154
|
|
155
155
|
it 'sets the deprecation warning flag to true' do
|
156
156
|
described_class.start(args)
|
@@ -159,7 +159,7 @@ describe ::Protobuf::CLI do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
context 'when disabled' do
|
162
|
-
let(:test_args) { [
|
162
|
+
let(:test_args) { ['--no-print_deprecation_warnings'] }
|
163
163
|
|
164
164
|
it 'sets the deprecation warning flag to false' do
|
165
165
|
described_class.start(args)
|
@@ -171,7 +171,7 @@ describe ::Protobuf::CLI do
|
|
171
171
|
context 'run modes' do
|
172
172
|
|
173
173
|
context 'socket' do
|
174
|
-
let(:test_args) { [
|
174
|
+
let(:test_args) { ['--socket'] }
|
175
175
|
let(:runner) { ::Protobuf::Rpc::SocketRunner }
|
176
176
|
|
177
177
|
before do
|
@@ -197,7 +197,7 @@ describe ::Protobuf::CLI do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
context 'zmq workers only' do
|
200
|
-
let(:test_args) { [
|
200
|
+
let(:test_args) { ['--workers_only', '--zmq'] }
|
201
201
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
202
202
|
|
203
203
|
before do
|
@@ -224,7 +224,7 @@ describe ::Protobuf::CLI do
|
|
224
224
|
end
|
225
225
|
|
226
226
|
context 'zmq worker port' do
|
227
|
-
let(:test_args) { [
|
227
|
+
let(:test_args) { ['--worker_port=1234', '--zmq'] }
|
228
228
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
229
229
|
|
230
230
|
before do
|
@@ -241,7 +241,7 @@ describe ::Protobuf::CLI do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
context 'zmq' do
|
244
|
-
let(:test_args) { [
|
244
|
+
let(:test_args) { ['--zmq'] }
|
245
245
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
246
246
|
|
247
247
|
before do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'protobuf/code_generator'
|
4
4
|
|
5
|
-
describe ::Protobuf::CodeGenerator do
|
5
|
+
RSpec.describe ::Protobuf::CodeGenerator do
|
6
6
|
|
7
7
|
# Some constants to shorten things up
|
8
8
|
DESCRIPTOR = ::Google::Protobuf
|
@@ -19,11 +19,11 @@ describe ::Protobuf::CodeGenerator do
|
|
19
19
|
let(:file_generator2) { double('file generator 2', :generate_output_file => output_file2) }
|
20
20
|
|
21
21
|
let(:request_bytes) do
|
22
|
-
COMPILER::CodeGeneratorRequest.encode(:proto_file => [
|
22
|
+
COMPILER::CodeGeneratorRequest.encode(:proto_file => [input_file1, input_file2])
|
23
23
|
end
|
24
24
|
|
25
25
|
let(:expected_response_bytes) do
|
26
|
-
COMPILER::CodeGeneratorResponse.encode(:file => [
|
26
|
+
COMPILER::CodeGeneratorResponse.encode(:file => [output_file1, output_file2])
|
27
27
|
end
|
28
28
|
|
29
29
|
before do
|
@@ -40,11 +40,11 @@ describe ::Protobuf::CodeGenerator do
|
|
40
40
|
context 'class-level printing methods' do
|
41
41
|
describe '.fatal' do
|
42
42
|
it 'raises a CodeGeneratorFatalError error' do
|
43
|
-
expect
|
43
|
+
expect do
|
44
44
|
described_class.fatal("something is wrong")
|
45
|
-
|
45
|
+
end.to raise_error(
|
46
46
|
::Protobuf::CodeGenerator::CodeGeneratorFatalError,
|
47
|
-
"something is wrong"
|
47
|
+
"something is wrong",
|
48
48
|
)
|
49
49
|
end
|
50
50
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Enum do
|
3
|
+
RSpec.describe Protobuf::Enum do
|
4
4
|
|
5
5
|
describe 'class dsl' do
|
6
6
|
let(:name) { :THREE }
|
@@ -40,40 +40,43 @@ describe Protobuf::Enum do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'allows defining enums with the same tag number' do
|
43
|
-
expect
|
43
|
+
expect do
|
44
44
|
DefineEnumAlias.define(:FOO, 1)
|
45
45
|
DefineEnumAlias.define(:BAR, 1)
|
46
|
-
|
46
|
+
end.not_to raise_error
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '.enums' do
|
52
52
|
it 'provides an array of defined Enums' do
|
53
|
-
expect(Test::EnumTestType.enums).to eq(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
expect(Test::EnumTestType.enums).to eq(
|
54
|
+
[
|
55
|
+
Test::EnumTestType::ONE,
|
56
|
+
Test::EnumTestType::TWO,
|
57
|
+
Test::EnumTestType::MINUS_ONE,
|
58
|
+
Test::EnumTestType::THREE,
|
59
|
+
],
|
60
|
+
)
|
59
61
|
end
|
60
62
|
|
61
63
|
context 'when enum allows aliases' do
|
62
64
|
it 'treats aliased enums as valid' do
|
63
|
-
expect(EnumAliasTest.enums).to eq(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
expect(EnumAliasTest.enums).to eq(
|
66
|
+
[
|
67
|
+
EnumAliasTest::FOO,
|
68
|
+
EnumAliasTest::BAR,
|
69
|
+
EnumAliasTest::BAZ,
|
70
|
+
],
|
71
|
+
)
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
|
-
|
73
76
|
describe '.enums_for_tag' do
|
74
77
|
it 'returns an array of Enums for the given tag, if any' do
|
75
|
-
expect(EnumAliasTest.enums_for_tag(1)).to eq([
|
76
|
-
expect(EnumAliasTest.enums_for_tag(2)).to eq([
|
78
|
+
expect(EnumAliasTest.enums_for_tag(1)).to eq([EnumAliasTest::FOO, EnumAliasTest::BAR])
|
79
|
+
expect(EnumAliasTest.enums_for_tag(2)).to eq([EnumAliasTest::BAZ])
|
77
80
|
expect(EnumAliasTest.enums_for_tag(3)).to eq([])
|
78
81
|
end
|
79
82
|
end
|
@@ -174,21 +177,26 @@ describe Protobuf::Enum do
|
|
174
177
|
end
|
175
178
|
|
176
179
|
describe '.values' do
|
180
|
+
around do |example|
|
181
|
+
# this method is deprecated
|
182
|
+
::Protobuf.deprecator.silence(&example)
|
183
|
+
end
|
184
|
+
|
177
185
|
it 'provides a hash of defined Enums' do
|
178
|
-
expect(Test::EnumTestType.values).to eq(
|
186
|
+
expect(Test::EnumTestType.values).to eq(
|
179
187
|
:MINUS_ONE => Test::EnumTestType::MINUS_ONE,
|
180
188
|
:ONE => Test::EnumTestType::ONE,
|
181
189
|
:TWO => Test::EnumTestType::TWO,
|
182
|
-
:THREE => Test::EnumTestType::THREE
|
183
|
-
|
190
|
+
:THREE => Test::EnumTestType::THREE,
|
191
|
+
)
|
184
192
|
end
|
185
193
|
|
186
194
|
it 'contains aliased Enums' do
|
187
|
-
expect(EnumAliasTest.values).to eq(
|
195
|
+
expect(EnumAliasTest.values).to eq(
|
188
196
|
:FOO => EnumAliasTest::FOO,
|
189
197
|
:BAR => EnumAliasTest::BAR,
|
190
|
-
:BAZ => EnumAliasTest::BAZ
|
191
|
-
|
198
|
+
:BAZ => EnumAliasTest::BAZ,
|
199
|
+
)
|
192
200
|
end
|
193
201
|
end
|
194
202
|
|
@@ -200,15 +208,24 @@ describe Protobuf::Enum do
|
|
200
208
|
end
|
201
209
|
end
|
202
210
|
|
203
|
-
|
211
|
+
subject { Test::EnumTestType::ONE }
|
204
212
|
specify { expect(subject.class).to eq(Fixnum) }
|
205
213
|
specify { expect(subject.parent_class).to eq(Test::EnumTestType) }
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
214
|
+
specify { expect(subject.name).to eq(:ONE) }
|
215
|
+
specify { expect(subject.tag).to eq(1) }
|
216
|
+
|
217
|
+
context 'deprecated' do
|
218
|
+
around do |example|
|
219
|
+
# this method is deprecated
|
220
|
+
::Protobuf.deprecator.silence(&example)
|
221
|
+
end
|
222
|
+
|
223
|
+
specify { expect(subject.value).to eq(1) }
|
224
|
+
end
|
225
|
+
|
226
|
+
specify { expect(subject.to_hash_value).to eq(1) }
|
227
|
+
specify { expect(subject.to_s).to eq("1") }
|
228
|
+
specify { expect(subject.inspect).to eq('#<Protobuf::Enum(Test::EnumTestType)::ONE=1>') }
|
212
229
|
specify { expect(subject.to_s(:tag)).to eq("1") }
|
213
230
|
specify { expect(subject.to_s(:name)).to eq("ONE") }
|
214
231
|
|
@@ -222,7 +239,16 @@ describe Protobuf::Enum do
|
|
222
239
|
specify { expect(subject.try(:class)).to eq(subject.class) }
|
223
240
|
specify { expect(subject.try(:name)).to eq(subject.name) }
|
224
241
|
specify { expect(subject.try(:tag)).to eq(subject.tag) }
|
225
|
-
|
242
|
+
|
243
|
+
context 'deprecated' do
|
244
|
+
around do |example|
|
245
|
+
# this method is deprecated
|
246
|
+
::Protobuf.deprecator.silence(&example)
|
247
|
+
end
|
248
|
+
|
249
|
+
specify { expect(subject.try(:value)).to eq(subject.value) }
|
250
|
+
end
|
251
|
+
|
226
252
|
specify { expect(subject.try(:to_i)).to eq(subject.to_i) }
|
227
253
|
specify { expect(subject.try(:to_int)).to eq(subject.to_int) }
|
228
254
|
specify { subject.try { |yielded| expect(yielded).to eq(subject) } }
|