protobuf-cucumber 3.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rubocop.yml +70 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +40 -0
  6. data/.yardopts +5 -0
  7. data/CHANGES.md +344 -0
  8. data/CONTRIBUTING.md +16 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +33 -0
  12. data/Rakefile +64 -0
  13. data/bin/protoc-gen-ruby +22 -0
  14. data/bin/rpc_server +5 -0
  15. data/install-protobuf.sh +28 -0
  16. data/lib/protobuf.rb +129 -0
  17. data/lib/protobuf/cli.rb +257 -0
  18. data/lib/protobuf/code_generator.rb +120 -0
  19. data/lib/protobuf/decoder.rb +28 -0
  20. data/lib/protobuf/deprecation.rb +117 -0
  21. data/lib/protobuf/descriptors.rb +3 -0
  22. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +62 -0
  23. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +301 -0
  24. data/lib/protobuf/encoder.rb +11 -0
  25. data/lib/protobuf/enum.rb +365 -0
  26. data/lib/protobuf/exceptions.rb +9 -0
  27. data/lib/protobuf/field.rb +74 -0
  28. data/lib/protobuf/field/base_field.rb +380 -0
  29. data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
  30. data/lib/protobuf/field/bool_field.rb +64 -0
  31. data/lib/protobuf/field/bytes_field.rb +78 -0
  32. data/lib/protobuf/field/double_field.rb +25 -0
  33. data/lib/protobuf/field/enum_field.rb +61 -0
  34. data/lib/protobuf/field/field_array.rb +104 -0
  35. data/lib/protobuf/field/field_hash.rb +122 -0
  36. data/lib/protobuf/field/fixed32_field.rb +25 -0
  37. data/lib/protobuf/field/fixed64_field.rb +28 -0
  38. data/lib/protobuf/field/float_field.rb +43 -0
  39. data/lib/protobuf/field/int32_field.rb +21 -0
  40. data/lib/protobuf/field/int64_field.rb +34 -0
  41. data/lib/protobuf/field/integer_field.rb +23 -0
  42. data/lib/protobuf/field/message_field.rb +51 -0
  43. data/lib/protobuf/field/sfixed32_field.rb +27 -0
  44. data/lib/protobuf/field/sfixed64_field.rb +28 -0
  45. data/lib/protobuf/field/signed_integer_field.rb +29 -0
  46. data/lib/protobuf/field/sint32_field.rb +21 -0
  47. data/lib/protobuf/field/sint64_field.rb +21 -0
  48. data/lib/protobuf/field/string_field.rb +51 -0
  49. data/lib/protobuf/field/uint32_field.rb +21 -0
  50. data/lib/protobuf/field/uint64_field.rb +21 -0
  51. data/lib/protobuf/field/varint_field.rb +77 -0
  52. data/lib/protobuf/generators/base.rb +85 -0
  53. data/lib/protobuf/generators/enum_generator.rb +39 -0
  54. data/lib/protobuf/generators/extension_generator.rb +27 -0
  55. data/lib/protobuf/generators/field_generator.rb +193 -0
  56. data/lib/protobuf/generators/file_generator.rb +262 -0
  57. data/lib/protobuf/generators/group_generator.rb +122 -0
  58. data/lib/protobuf/generators/message_generator.rb +104 -0
  59. data/lib/protobuf/generators/option_generator.rb +17 -0
  60. data/lib/protobuf/generators/printable.rb +160 -0
  61. data/lib/protobuf/generators/service_generator.rb +50 -0
  62. data/lib/protobuf/lifecycle.rb +33 -0
  63. data/lib/protobuf/logging.rb +39 -0
  64. data/lib/protobuf/message.rb +260 -0
  65. data/lib/protobuf/message/fields.rb +233 -0
  66. data/lib/protobuf/message/serialization.rb +85 -0
  67. data/lib/protobuf/optionable.rb +70 -0
  68. data/lib/protobuf/rpc/buffer.rb +78 -0
  69. data/lib/protobuf/rpc/client.rb +140 -0
  70. data/lib/protobuf/rpc/connectors/base.rb +221 -0
  71. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  72. data/lib/protobuf/rpc/connectors/socket.rb +78 -0
  73. data/lib/protobuf/rpc/connectors/zmq.rb +319 -0
  74. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +50 -0
  75. data/lib/protobuf/rpc/env.rb +60 -0
  76. data/lib/protobuf/rpc/error.rb +28 -0
  77. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  78. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  79. data/lib/protobuf/rpc/middleware.rb +25 -0
  80. data/lib/protobuf/rpc/middleware/exception_handler.rb +40 -0
  81. data/lib/protobuf/rpc/middleware/logger.rb +95 -0
  82. data/lib/protobuf/rpc/middleware/request_decoder.rb +79 -0
  83. data/lib/protobuf/rpc/middleware/response_encoder.rb +83 -0
  84. data/lib/protobuf/rpc/middleware/runner.rb +18 -0
  85. data/lib/protobuf/rpc/rpc.pb.rb +64 -0
  86. data/lib/protobuf/rpc/rpc_method.rb +16 -0
  87. data/lib/protobuf/rpc/server.rb +39 -0
  88. data/lib/protobuf/rpc/servers/socket/server.rb +121 -0
  89. data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
  90. data/lib/protobuf/rpc/servers/socket_runner.rb +46 -0
  91. data/lib/protobuf/rpc/servers/zmq/broker.rb +194 -0
  92. data/lib/protobuf/rpc/servers/zmq/server.rb +321 -0
  93. data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
  94. data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
  95. data/lib/protobuf/rpc/servers/zmq_runner.rb +70 -0
  96. data/lib/protobuf/rpc/service.rb +172 -0
  97. data/lib/protobuf/rpc/service_directory.rb +261 -0
  98. data/lib/protobuf/rpc/service_dispatcher.rb +45 -0
  99. data/lib/protobuf/rpc/service_filters.rb +250 -0
  100. data/lib/protobuf/rpc/stat.rb +119 -0
  101. data/lib/protobuf/socket.rb +21 -0
  102. data/lib/protobuf/tasks.rb +1 -0
  103. data/lib/protobuf/tasks/compile.rake +80 -0
  104. data/lib/protobuf/varint.rb +20 -0
  105. data/lib/protobuf/varint_pure.rb +31 -0
  106. data/lib/protobuf/version.rb +3 -0
  107. data/lib/protobuf/wire_type.rb +10 -0
  108. data/lib/protobuf/zmq.rb +21 -0
  109. data/profile.html +5103 -0
  110. data/proto/dynamic_discovery.proto +44 -0
  111. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  112. data/proto/google/protobuf/descriptor.proto +779 -0
  113. data/proto/rpc.proto +69 -0
  114. data/protobuf-cucumber.gemspec +57 -0
  115. data/spec/benchmark/tasks.rb +143 -0
  116. data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
  117. data/spec/encoding/all_types_spec.rb +103 -0
  118. data/spec/encoding/extreme_values_spec.rb +0 -0
  119. data/spec/functional/class_inheritance_spec.rb +52 -0
  120. data/spec/functional/code_generator_spec.rb +58 -0
  121. data/spec/functional/socket_server_spec.rb +59 -0
  122. data/spec/functional/zmq_server_spec.rb +105 -0
  123. data/spec/lib/protobuf/cli_spec.rb +317 -0
  124. data/spec/lib/protobuf/code_generator_spec.rb +87 -0
  125. data/spec/lib/protobuf/enum_spec.rb +307 -0
  126. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  127. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/enum_field_spec.rb +44 -0
  129. data/spec/lib/protobuf/field/field_array_spec.rb +105 -0
  130. data/spec/lib/protobuf/field/field_hash_spec.rb +168 -0
  131. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  134. data/spec/lib/protobuf/field/int32_field_spec.rb +120 -0
  135. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  136. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  137. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  138. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  139. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  140. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  141. data/spec/lib/protobuf/field/string_field_spec.rb +79 -0
  142. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  143. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  144. data/spec/lib/protobuf/field_spec.rb +192 -0
  145. data/spec/lib/protobuf/generators/base_spec.rb +154 -0
  146. data/spec/lib/protobuf/generators/enum_generator_spec.rb +82 -0
  147. data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
  148. data/spec/lib/protobuf/generators/field_generator_spec.rb +197 -0
  149. data/spec/lib/protobuf/generators/file_generator_spec.rb +119 -0
  150. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  151. data/spec/lib/protobuf/generators/service_generator_spec.rb +99 -0
  152. data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
  153. data/spec/lib/protobuf/message_spec.rb +944 -0
  154. data/spec/lib/protobuf/optionable_spec.rb +265 -0
  155. data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
  156. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +226 -0
  157. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  158. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +34 -0
  159. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +110 -0
  160. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
  161. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
  162. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
  163. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +91 -0
  164. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
  165. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +43 -0
  166. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
  167. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
  168. data/spec/lib/protobuf/rpc/service_directory_spec.rb +293 -0
  169. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +35 -0
  170. data/spec/lib/protobuf/rpc/service_filters_spec.rb +517 -0
  171. data/spec/lib/protobuf/rpc/service_spec.rb +162 -0
  172. data/spec/lib/protobuf/rpc/stat_spec.rb +101 -0
  173. data/spec/lib/protobuf/varint_spec.rb +29 -0
  174. data/spec/lib/protobuf_spec.rb +105 -0
  175. data/spec/spec_helper.rb +42 -0
  176. data/spec/support/all.rb +6 -0
  177. data/spec/support/packed_field.rb +23 -0
  178. data/spec/support/protos/all_types.data.bin +0 -0
  179. data/spec/support/protos/all_types.data.txt +119 -0
  180. data/spec/support/protos/enum.pb.rb +63 -0
  181. data/spec/support/protos/enum.proto +37 -0
  182. data/spec/support/protos/extreme_values.data.bin +0 -0
  183. data/spec/support/protos/google_unittest.bin +0 -0
  184. data/spec/support/protos/google_unittest.pb.rb +798 -0
  185. data/spec/support/protos/google_unittest.proto +884 -0
  186. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  187. data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
  188. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  189. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  190. data/spec/support/protos/google_unittest_import.proto +73 -0
  191. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  192. data/spec/support/protos/google_unittest_import_public.proto +41 -0
  193. data/spec/support/protos/map-test.bin +157 -0
  194. data/spec/support/protos/map-test.pb.rb +85 -0
  195. data/spec/support/protos/map-test.proto +68 -0
  196. data/spec/support/protos/multi_field_extensions.pb.rb +59 -0
  197. data/spec/support/protos/multi_field_extensions.proto +35 -0
  198. data/spec/support/protos/resource.pb.rb +172 -0
  199. data/spec/support/protos/resource.proto +137 -0
  200. data/spec/support/resource_service.rb +23 -0
  201. data/spec/support/server.rb +65 -0
  202. data/spec/support/test_app_file.rb +2 -0
  203. data/varint_prof.rb +82 -0
  204. metadata +579 -0
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Int64Field do
4
+
5
+ it_behaves_like :packable_field, described_class
6
+
7
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::MessageField do
4
+ let(:inner_message) do
5
+ Class.new(::Protobuf::Message) do
6
+ optional :int32, :field, 0
7
+ optional :int32, :field2, 1
8
+ end
9
+ end
10
+
11
+ let(:field_message) do
12
+ Class.new(::Protobuf::Message) do
13
+ optional :int32, :field, 1
14
+ repeated :int64, :repeated_field, 2
15
+ optional InnerMessage, :message_field, 3
16
+ end
17
+ end
18
+
19
+ let(:message) do
20
+ Class.new(::Protobuf::Message) do
21
+ optional FieldMessage, :message_field, 1
22
+ end
23
+ end
24
+
25
+ before do
26
+ stub_const('InnerMessage', inner_message)
27
+ stub_const('FieldMessage', field_message)
28
+ stub_const('Message', message)
29
+ end
30
+
31
+ let(:instance) { message.new }
32
+
33
+ describe 'setting and getting field' do
34
+ context "when set with the message type" do
35
+ it 'is readable as a message' do
36
+ value = field_message.new(:field => 34)
37
+ instance.message_field = value
38
+ expect(instance.message_field).to eq(value)
39
+ end
40
+ end
41
+
42
+ context "when set with #to_proto" do
43
+ let(:to_proto_message) do
44
+ Class.new do
45
+ def to_proto
46
+ FieldMessage.new(:field => 42)
47
+ end
48
+ end
49
+ end
50
+
51
+ it 'is readable as a message' do
52
+ value = to_proto_message.new
53
+ instance.message_field = value
54
+ expect(instance.message_field).to eq(value.to_proto)
55
+ end
56
+ end
57
+
58
+ context "when set with #to_proto that returns the wrong message type" do
59
+ let(:to_proto_is_wrong_message) do
60
+ Class.new do
61
+ def to_proto
62
+ Message.new
63
+ end
64
+ end
65
+ end
66
+
67
+ it 'fails' do
68
+ value = to_proto_is_wrong_message.new
69
+ expect { instance.message_field = value }.to raise_error TypeError
70
+ end
71
+ end
72
+
73
+ context "when set with #to_hash" do
74
+ let(:to_hash_message) do
75
+ Class.new do
76
+ def to_hash
77
+ { :field => 989 }
78
+ end
79
+ end
80
+ end
81
+
82
+ it 'is readable as a message' do
83
+ value = to_hash_message.new
84
+ instance.message_field = value
85
+ expect(instance.message_field).to eq(field_message.new(value.to_hash))
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#option_set' do
91
+ let(:message_field) { Message.fields[0] }
92
+ it 'returns unless yield' do
93
+ # No Error thrown
94
+ message_field.__send__(:option_set, nil, nil, nil) { false }
95
+ expect do
96
+ message_field.__send__(:option_set, nil, nil, nil) { true }
97
+ end.to raise_error StandardError
98
+ end
99
+
100
+ it 'sets repeated fields' do
101
+ repeated = field_message.fields[1]
102
+ instance = field_message.new
103
+ expect(instance.repeated_field!).to eq(nil)
104
+ message_field.__send__(:option_set, instance, repeated, [53]) { true }
105
+ expect(instance.repeated_field!).to eq([53])
106
+ message_field.__send__(:option_set, instance, repeated, [54]) { true }
107
+ expect(instance.repeated_field!).to eq([53, 54])
108
+ end
109
+
110
+ it 'sets optional non-message fields' do
111
+ optional = field_message.fields[0]
112
+ instance = field_message.new
113
+ expect(instance.field!).to eq(nil)
114
+ message_field.__send__(:option_set, instance, optional, 53) { true }
115
+ expect(instance.field!).to eq(53)
116
+ message_field.__send__(:option_set, instance, optional, 52) { true }
117
+ expect(instance.field!).to eq(52)
118
+ end
119
+
120
+ it 'sets nested inner messages fields one at a time' do
121
+ inner = field_message.fields[2]
122
+ inner_val = InnerMessage.new(:field => 21)
123
+ inner_val2 = InnerMessage.new(:field2 => 9)
124
+ instance = field_message.new
125
+ expect(instance.message_field!).to eq(nil)
126
+ message_field.__send__(:option_set, instance, inner, inner_val) { true }
127
+ expect(instance.message_field!).to eq(InnerMessage.new(:field => 21))
128
+ message_field.__send__(:option_set, instance, inner, inner_val2) { true }
129
+ expect(instance.message_field!).to eq(InnerMessage.new(:field => 21, :field2 => 9))
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Sfixed32Field do
4
+
5
+ it_behaves_like :packable_field, described_class do
6
+ let(:value) { [-1, 0, 1] }
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Sfixed64Field do
4
+
5
+ it_behaves_like :packable_field, described_class do
6
+ let(:value) { [-1, 0, 1] }
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Sint32Field do
4
+
5
+ it_behaves_like :packable_field, described_class do
6
+ let(:value) { [-1, 0, 1] }
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Sint64Field do
4
+
5
+ it_behaves_like :packable_field, described_class do
6
+ let(:value) { [-1, 0, 1] }
7
+ end
8
+
9
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe ::Protobuf::Field::StringField do
6
+
7
+ describe '#encode' do
8
+ context 'when a repeated string field contains frozen strings' do
9
+ it 'does not raise an encoding error' do
10
+ expect do
11
+ frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze]
12
+ ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings)
13
+ end.not_to raise_error
14
+ end
15
+ end
16
+
17
+ context 'when a repeated bytes field contains frozen strings' do
18
+ it 'does not raise an encoding error' do
19
+ expect do
20
+ frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze]
21
+ ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings)
22
+ end.not_to raise_error
23
+ end
24
+ end
25
+
26
+ it 'does not alter string values after encoding multiple times' do
27
+ source_string = "foo"
28
+ proto = ::Test::Resource.new(:name => source_string)
29
+ proto.encode
30
+ expect(proto.name).to eq source_string
31
+ proto.encode
32
+ expect(proto.name).to eq source_string
33
+ end
34
+
35
+ it 'does not alter unicode string values after encoding multiple times' do
36
+ source_string = "¢"
37
+ proto = ::Test::Resource.new(:name => source_string)
38
+ proto.encode
39
+ expect(proto.name).to eq source_string
40
+ proto.encode
41
+ expect(proto.name).to eq source_string
42
+ end
43
+ end
44
+
45
+ describe '#default_value' do
46
+ context 'optional and required fields' do
47
+ it 'returns the class default' do
48
+ class SomeStringMessage < ::Protobuf::Message
49
+ optional :string, :some_string, 1
50
+ end
51
+ expect(SomeStringMessage.get_field('some_string').default).to be nil
52
+ expect(::Protobuf::Field::StringField.default).to eq ""
53
+ expect(SomeStringMessage.new.some_string).to eq ""
54
+ end
55
+
56
+ context 'with field default' do
57
+ class AnotherStringMessage < ::Protobuf::Message
58
+ optional :string, :set_string, 1, :default => "default value this is"
59
+ end
60
+
61
+ it 'returns the set default' do
62
+ expect(AnotherStringMessage.get_field('set_string').default).to eq "default value this is"
63
+ expect(AnotherStringMessage.new.set_string).to eq "default value this is"
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'repeated field' do
69
+ class RepeatedStringMessage < ::Protobuf::Message
70
+ repeated :string, :repeated_string, 1
71
+ end
72
+
73
+ it 'returns the set default' do
74
+ expect(RepeatedStringMessage.new.repeated_string).to eq []
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Uint32Field do
4
+
5
+ it_behaves_like :packable_field, described_class
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Protobuf::Field::Uint64Field do
4
+
5
+ it_behaves_like :packable_field, described_class
6
+
7
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+ require 'protobuf/field'
3
+ require PROTOS_PATH.join('resource.pb')
4
+
5
+ RSpec.describe ::Protobuf::Field do
6
+
7
+ describe '.build' do
8
+ pending
9
+ end
10
+
11
+ describe '.field_class' do
12
+ context 'when type is an enum class' do
13
+ it 'returns an enum field' do
14
+ expect(subject.field_class(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField)
15
+ expect(subject.field_type(::Test::EnumTestType)).to eq(::Test::EnumTestType)
16
+ end
17
+ end
18
+
19
+ context 'when type is a message class' do
20
+ it 'returns a message field' do
21
+ expect(subject.field_class(::Test::Resource)).to eq(::Protobuf::Field::MessageField)
22
+ expect(subject.field_type(::Test::Resource)).to eq(::Test::Resource)
23
+ end
24
+ end
25
+
26
+ context 'when type is a base field class' do
27
+ it 'returns that class' do
28
+ expect(subject.field_class(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField)
29
+ end
30
+ end
31
+
32
+ context 'when type is a double field class or symbol' do
33
+ it 'returns that class' do
34
+ expected_field = ::Protobuf::Field::DoubleField
35
+ expect(subject.field_class(expected_field)).to eq(expected_field)
36
+ expect(subject.field_class(:double)).to eq(expected_field)
37
+ expect(subject.field_type(expected_field)).to eq(expected_field)
38
+ expect(subject.field_type(:double)).to eq(expected_field)
39
+ end
40
+ end
41
+
42
+ context 'when type is a float field class or symbol' do
43
+ it 'returns that class' do
44
+ expected_field = ::Protobuf::Field::FloatField
45
+ expect(subject.field_class(expected_field)).to eq(expected_field)
46
+ expect(subject.field_class(:float)).to eq(expected_field)
47
+ expect(subject.field_type(expected_field)).to eq(expected_field)
48
+ expect(subject.field_type(:float)).to eq(expected_field)
49
+ end
50
+ end
51
+
52
+ context 'when type is a int32 field class or symbol' do
53
+ it 'returns that class' do
54
+ expected_field = ::Protobuf::Field::Int32Field
55
+ expect(subject.field_class(expected_field)).to eq(expected_field)
56
+ expect(subject.field_class(:int32)).to eq(expected_field)
57
+ expect(subject.field_type(expected_field)).to eq(expected_field)
58
+ expect(subject.field_type(:int32)).to eq(expected_field)
59
+ end
60
+ end
61
+
62
+ context 'when type is a int64 field class or symbol' do
63
+ it 'returns that class' do
64
+ expected_field = ::Protobuf::Field::Int64Field
65
+ expect(subject.field_class(expected_field)).to eq(expected_field)
66
+ expect(subject.field_class(:int64)).to eq(expected_field)
67
+ expect(subject.field_type(expected_field)).to eq(expected_field)
68
+ expect(subject.field_type(:int64)).to eq(expected_field)
69
+ end
70
+ end
71
+
72
+ context 'when type is a uint32 field class or symbol' do
73
+ it 'returns that class' do
74
+ expected_field = ::Protobuf::Field::Uint32Field
75
+ expect(subject.field_class(expected_field)).to eq(expected_field)
76
+ expect(subject.field_class(:uint32)).to eq(expected_field)
77
+ expect(subject.field_type(expected_field)).to eq(expected_field)
78
+ expect(subject.field_type(:uint32)).to eq(expected_field)
79
+ end
80
+ end
81
+
82
+ context 'when type is a uint64 field class or symbol' do
83
+ it 'returns that class' do
84
+ expected_field = ::Protobuf::Field::Uint64Field
85
+ expect(subject.field_class(expected_field)).to eq(expected_field)
86
+ expect(subject.field_class(:uint64)).to eq(expected_field)
87
+ expect(subject.field_type(expected_field)).to eq(expected_field)
88
+ expect(subject.field_type(:uint64)).to eq(expected_field)
89
+ end
90
+ end
91
+
92
+ context 'when type is a sint32 field class or symbol' do
93
+ it 'returns that class' do
94
+ expected_field = ::Protobuf::Field::Sint32Field
95
+ expect(subject.field_class(expected_field)).to eq(expected_field)
96
+ expect(subject.field_class(:sint32)).to eq(expected_field)
97
+ expect(subject.field_type(expected_field)).to eq(expected_field)
98
+ expect(subject.field_type(:sint32)).to eq(expected_field)
99
+ end
100
+ end
101
+
102
+ context 'when type is a sint64 field class or symbol' do
103
+ it 'returns that class' do
104
+ expected_field = ::Protobuf::Field::Sint64Field
105
+ expect(subject.field_class(expected_field)).to eq(expected_field)
106
+ expect(subject.field_class(:sint64)).to eq(expected_field)
107
+ expect(subject.field_type(expected_field)).to eq(expected_field)
108
+ expect(subject.field_type(:sint64)).to eq(expected_field)
109
+ end
110
+ end
111
+
112
+ context 'when type is a fixed32 field class or symbol' do
113
+ it 'returns that class' do
114
+ expected_field = ::Protobuf::Field::Fixed32Field
115
+ expect(subject.field_class(expected_field)).to eq(expected_field)
116
+ expect(subject.field_class(:fixed32)).to eq(expected_field)
117
+ expect(subject.field_type(expected_field)).to eq(expected_field)
118
+ expect(subject.field_type(:fixed32)).to eq(expected_field)
119
+ end
120
+ end
121
+
122
+ context 'when type is a fixed64 field class or symbol' do
123
+ it 'returns that class' do
124
+ expected_field = ::Protobuf::Field::Fixed64Field
125
+ expect(subject.field_class(expected_field)).to eq(expected_field)
126
+ expect(subject.field_class(:fixed64)).to eq(expected_field)
127
+ expect(subject.field_type(expected_field)).to eq(expected_field)
128
+ expect(subject.field_type(:fixed64)).to eq(expected_field)
129
+ end
130
+ end
131
+
132
+ context 'when type is a sfixed32 field class or symbol' do
133
+ it 'returns that class' do
134
+ expected_field = ::Protobuf::Field::Sfixed32Field
135
+ expect(subject.field_class(expected_field)).to eq(expected_field)
136
+ expect(subject.field_class(:sfixed32)).to eq(expected_field)
137
+ expect(subject.field_type(expected_field)).to eq(expected_field)
138
+ expect(subject.field_type(:sfixed32)).to eq(expected_field)
139
+ end
140
+ end
141
+
142
+ context 'when type is a sfixed64 field class or symbol' do
143
+ it 'returns that class' do
144
+ expected_field = ::Protobuf::Field::Sfixed64Field
145
+ expect(subject.field_class(expected_field)).to eq(expected_field)
146
+ expect(subject.field_class(:sfixed64)).to eq(expected_field)
147
+ expect(subject.field_type(expected_field)).to eq(expected_field)
148
+ expect(subject.field_type(:sfixed64)).to eq(expected_field)
149
+ end
150
+ end
151
+
152
+ context 'when type is a string field class or symbol' do
153
+ it 'returns that class' do
154
+ expected_field = ::Protobuf::Field::StringField
155
+ expect(subject.field_class(expected_field)).to eq(expected_field)
156
+ expect(subject.field_class(:string)).to eq(expected_field)
157
+ expect(subject.field_type(expected_field)).to eq(expected_field)
158
+ expect(subject.field_type(:string)).to eq(expected_field)
159
+ end
160
+ end
161
+
162
+ context 'when type is a bytes field class or symbol' do
163
+ it 'returns that class' do
164
+ expected_field = ::Protobuf::Field::BytesField
165
+ expect(subject.field_class(expected_field)).to eq(expected_field)
166
+ expect(subject.field_class(:bytes)).to eq(expected_field)
167
+ expect(subject.field_type(expected_field)).to eq(expected_field)
168
+ expect(subject.field_type(:bytes)).to eq(expected_field)
169
+ end
170
+ end
171
+
172
+ context 'when type is a bool field class or symbol' do
173
+ it 'returns that class' do
174
+ expected_field = ::Protobuf::Field::BoolField
175
+ expect(subject.field_class(expected_field)).to eq(expected_field)
176
+ expect(subject.field_class(:bool)).to eq(expected_field)
177
+ expect(subject.field_type(expected_field)).to eq(expected_field)
178
+ expect(subject.field_type(:bool)).to eq(expected_field)
179
+ end
180
+ end
181
+
182
+ context 'when type is not mapped' do
183
+ it 'raises an ArgumentError' do
184
+ expect do
185
+ subject.field_class("boom")
186
+ end.to raise_error(ArgumentError)
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end